HTTP Endpoints
HTTP Endpoints
Here's an example of HTTP endpoint definition:
The http
field of the spec is a dictionary where each item represents an API.
API
API is a logical grouping of endpoints. This grouping is important for code generation as it allows to split code into logically separate files/classes.
Each key in the http
dictionary is a name of the API and value is a dictionary defining endpoints belonging to the API.
Here's an example of two APIs books
and authors
with two endpoints in each.
Endpoint
Here's an example of endpoint definition:
Here's information about endpoint definition fields:
Endpoint Field
Endpoint defines HTTP method and URL to which service should respond.
Endpoint has the following format: METHOD url
. Method might be one of follwing: GET
, POST
, PUT
, DELETE
.
Url is just a string always starting from /
. Url can contain parameters in following format: {param:type}
. Here's an example for enpoint with url parameter:
Parameters
This section describes parameters format that is used for both header parameters and query parameters.
Here's an example of parameter page_size
of type int
default value 20
and description number of items per page
:
Here's an example of parameter page
of type int
without default value or description:
Header Parameters
The header
field of endpoint allows to define HTTP header parameters. The header
field value is a dictionary where each item is using parameters format.
Here's an example of two header parameters definition: Authorization
(string
) and X-Request-Id
(uuid
):
Omit header
field in endpoint defintion if there no header parameters needed.
Query Parameters
The query
field of endpoint allows to define HTTP header parameters. The query
field value is a dictionary where each item is using parameters format.
Here's an example of two query parameters definition: page_size
(int
) and page_number
(int
):
Omit query
field in endpoint defintion if there no query parameters needed.
Request Body
The body
field of endpoint defines body type of HTTP endpoint request.
Here's an example of body definition represented by custom type Sample
:
The body
field can not have default value. Omit body
field in endpoint definition if request body is not required.
Response
Here's an example of response definition with 2 responses: ok
and forbidden
, the ok
response has a body of type Sample
along with descriptions:
The response
field of endpoint defines all possible responses of the HTTP endpointed. The response
is a dictionary where key is the name of the response and value is the type of the response. Responses names should be in a text form according to RFC 7231 but in snake_case
. So, OK
will be ok
, Unauthorized
- unauthorized
, Method Not Allowed
- method_not_allowed
, etc.
At least one response should be always defined for any HTTP endpoint.
Last updated