Skip to content

Write a Resource() function that takes a struct that implements new interface ResourceInterface #14

Description

@ishehata

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions