api

package
v0.0.0-...-88c334c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

README

API

This directory contains the API specification and all files necessary to build API artifacts. API definitions use gRPC tools for consistent and quality tooling. Within the oracles (middleware), we use grpc-gateway to expose a REST/JSON API (documented in the swagger file) that is transcoded to a gRPC service that is consumed internally.

Entity types and endpoints are defined in protobuf and gRPC. This has several advantages over editing the swagger file directly, including:

  • Clean diffs.
  • Better backwards compatibilty through field numbers.
  • Clear semantics for objects and repeated fields.

Directory Structure

pb:
	Protobuf speciations for entities, models, and messages used and referenced
	in various API endpoints.
srvpb:
	Endpoint specifications (in gRPC format with HTTP/swagger annotations).
swagger:
	Generated swagger JSON and a Go package that serves the json to frontend
	clients.

Generating gRPC service code and Swagger/OpenAPI documentation

The generated gRPC service code, gateway code, and the swagger file are checked into git. After every change you should regenerate these files and check them in. Run make in the api directory to regenerate these files.

make

Among the generated output is a swagger file, swagger/oracle.swagger.json. Do not edit this file directly or it will be replaced the next time any .proto files are modifieed.

Viewing REST API documentation

Use your favorite OpenAPI/Swagger tool to view the swagger file generated above at swagger/oracle.swagger.json. One such tool is redoc. To view the swagger file using redoc, you need to install the CLI first:

brew install npm
npm i -g redoc-cli

Run make redoc at the root of the project to view the User API spec. The port has been set to not conflict with Oracle. You can also run redoc directly:

npx redoc-cli serve -p 57505 ./api/swagger/oracle.swagger.json

Use the swagger editor to view the swagger specification online.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPHandler

func HTTPHandler(svc string) (http.Handler, error)

HTTPHandler returns an endpoint handler that writes the specified swagger service definition to w.

Types

This section is empty.

Directories

Path Synopsis
pb
v1
srvpb
v1
Package srv is a reverse proxy.
Package srv is a reverse proxy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL