rest

package module
v2.2.3+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2018 License: MIT Imports: 6 Imported by: 5

README

rest

CircleCI Go Report Card godoc

Package rest it's tiny lightweight package which helps to work with RESTful API and JSON API.

Installation

go get -u github.com/thepkg/rest

Usage

import "github.com/thepkg/rest"

func main() {
	rest.GET("/users", func(w http.ResponseWriter, r *http.Request) {
		rest.Success(w, http.StatusOK, "find")
	})

	rest.POST("/users", func(w http.ResponseWriter, r *http.Request) {
		rest.Success(w, http.StatusOK, "create")
	})

	rest.PUT("/users", func(w http.ResponseWriter, r *http.Request) {
		rest.Error(w, http.StatusMethodNotAllowed, "update not allowed")
	})

	rest.DELETE("/users", func(w http.ResponseWriter, r *http.Request) {
		rest.Error(w, http.StatusMethodNotAllowed, "delete not allowed")
	})

	http.ListenAndServe(":8080", nil)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DELETE

func DELETE(pattern string, handler func(http.ResponseWriter, *http.Request))

DELETE registers the DELETE HTTP method handler function for the given pattern.

func Error

func Error(w http.ResponseWriter, code int, data interface{})

Error sends error HTTP response.

func GET

func GET(pattern string, handler func(http.ResponseWriter, *http.Request))

GET registers the GET HTTP method handler function for the given pattern.

func HEAD(pattern string, handler func(http.ResponseWriter, *http.Request))

HEAD registers the HEAD HTTP method handler function for the given pattern.

func MustUnmarshalBody

func MustUnmarshalBody(r *http.Request, data interface{})

MustUnmarshalBody performs read and json.Unmarshal body into data.

func OPTIONS

func OPTIONS(pattern string, handler func(http.ResponseWriter, *http.Request))

OPTIONS registers the OPTIONS HTTP method handler function for the given pattern.

func PATCH

func PATCH(pattern string, handler func(http.ResponseWriter, *http.Request))

PATCH registers the PATCH HTTP method handler function for the given pattern.

func POST

func POST(pattern string, handler func(http.ResponseWriter, *http.Request))

POST registers the POST HTTP method handler function for the given pattern.

func PUT

func PUT(pattern string, handler func(http.ResponseWriter, *http.Request))

PUT registers the PUT HTTP method handler function for the given pattern.

func Success

func Success(w http.ResponseWriter, code int, data interface{})

Success sends successful HTTP response.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL