Write a new router function called Resource( ) that automatically register REST APIs to the router using handlers from a struct that implements a new interface called ResourceInterface or SingleResourceInterface.
e.g:
type ResourceInterface interface {
List(http.ResponseWriter, *http.Request)
Create(http.ResponseWriter, *http.Request)
Single(http.ResponseWriter, *http.Request)
Put(http.ResponseWriter, *http.Request)
Patch(http.ResponseWriter, *http.Request)
Delete(http.ResponseWriter, *http.Request)
}
and using the router the registration could be something like:
users := UsersResource{} // a struct that implements Resource Interface
router.Resource('/users', &users)
and that would automatically register the following routes:
GET /users/ => users.List()
POST /users/ => users.Create()
GET /users/:id => users.Single()
PUT /users/:id => users.Put()
PATCH /users/:id => users.Patch()
DELETE /users/:id => users.Delete()
Write a new router function called Resource( ) that automatically register REST APIs to the router using handlers from a struct that implements a new interface called ResourceInterface or SingleResourceInterface.
e.g:
and using the router the registration could be something like:
and that would automatically register the following routes: