HTTP Endpoints
Last updated
Last updated
Here's an example of HTTP endpoint definition:
The http
field of the spec is a dictionary where each item represents an .
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 belonging to the API.
Here's an example of two APIs books
and authors
with two endpoints in each.
Here's an example of endpoint definition:
Here's information about endpoint definition fields:
description
no
description, used for documentation
yes
HTTP method and endpoint URL
no
dictionary of HTTP header parameters and their types
no
dictionary of HTTP query parameters and their types
no for POST and PUT
HTTP body of the request
yes
dictionary of supported HTTP responses and response body
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:
parameter
yes
parameter name
type
yes
default_value
no
default value for the parameter
description
no
description in a form of line comment, used for documentation
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:
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.
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.
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.
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:
At least one response should be always defined for any HTTP endpoint.
This section describes parameters format that is used for both and .
type of parameter according to
The header
field of allows to define HTTP header parameters. The header
field value is a dictionary where each item is using format.
The query
field of allows to define HTTP header parameters. The query
field value is a dictionary where each item is using format.
The body
field of defines body type of HTTP endpoint request.
The response
field of 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 but in snake_case
. So, OK
will be ok
, Unauthorized
- unauthorized
, Method Not Allowed
- method_not_allowed
, etc.