Skip to content
/ api Public

📐 Automatically implements your REST API.

License

Notifications You must be signed in to change notification settings

aerogo/api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api

Godoc Report Tests Coverage Sponsor

Automatically implements your REST API.

Usage

Create an API instance

myAPI := api.New("/api/", DB)

Parameters:

  • The root of all your API routes
  • A database handle that fulfills the Database interface

Install on an Aero app

myAPI.Install(app)

This will register all API routes in the app.

Routes

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.

GET /api/movie/:id

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.

POST /api/movie/:id

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:

POST /api/new/movie

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.

Style

Please take a look at the style guidelines if you'd like to make a pull request.

Sponsors

Cedric Fung Scott Rayapoullé Eduard Urbach
Cedric Fung Scott Rayapoullé Eduard Urbach

Want to see your own name here?

About

📐 Automatically implements your REST API.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages