Skip to content

Latest commit

 

History

History
 
 

rest

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Flow Access Node HTTP API Server

This package and subpackages implement the HTTP API Server for the Flow OpenAPI definition. The API documentation is available on our docs site.

Packages

  • rest: The HTTP handlers for all the request, server generator and the select filter.
  • middleware: The common middlewares that all request pass through.
  • models: The generated models using openapi generators and implementation of model builders.
  • request: Implementation of API requests that provide validation for input data and build request models.

Request lifecycle

  1. Every incoming request passes through a common set of middlewares - logging middleware, query expandable and query select middleware defined in the middleware package.
  2. Each request is then wrapped by our handler (rest/handler.go) and request input data is used to build the request models defined in request package.
  3. The request is then sent to the corresponding API handler based on the configuration in the router.
  4. Each handler implements actions to perform the request (database lookups etc) and after the response is built using the model builders defined in models package.
  5. Returned value is then again handled by our wrapped handler making sure to correctly handle successful and failure responses.

Maintaining

Updating OpenAPI Schema

Make sure the OpenAPI schema if first updated and merged into master on the hosted repository. After you can use the make command to generated updated models:

make generate-openapi

Adding New API Endpoints

A new endpoint can be added by first implementing a new request handler, a request handle is a function in the rest package that complies with function interfaced defined as:

type ApiHandlerFunc func (
r *request.Request,
backend access.API,
generator models.LinkGenerator,
) (interface{}, error)

That handler implementation needs to be added to the router.go with corresponding API endpoint and method. Adding a new API endpoint also requires for a new request builder to be implemented and added in request package. Make sure to not forget about adding tests for each of the API handler.