Automatically implements your REST API.
myAPI := api.New("/api/", DB)
Parameters:
- The root of all your API routes
- A database handle that fulfills the Database interface
myAPI.Install(app)
This will register all API routes in the app.
For the following examples we'll assume you have the type Movie
registered in the database and that your API root is /api/
. Type names are automatically lowercased for all routes.
Action: get
Fetches the object with the given ID from the database and shows the JSON representation.
Example response:
If you need to filter out sensitive or private data you can implement the Filter interface on the data type.
Action: edit
Writes new data to the object with the given ID. The data needs to be a JSON-formatted map[string]interface
where each key stands for a path to a field of this object. The data type needs to implement the Editable interface. Editable fields must be whitelisted with the tag editable
using the value true
.
Example request:
Alternate example using advanced key paths:
Action: create
Create a new object of that data type. The data type needs to implement the Creatable interface to register that route. Usually the post body contains a JSON-formatted key/value map which is used as the initial data for the new object.
Example request:
It is up to the developer how the data is interpreted. This API library doesn't make any assumptions about the POST body in create
requests.
Please take a look at the style guidelines if you'd like to make a pull request.
Cedric Fung | Scott Rayapoullé | Eduard Urbach |
Want to see your own name here?