Sobes.tech
Junior — Middle

What types of contracts are used when creating REST API?

sobes.tech AI

Answer from AI

The main types of contracts used in REST API creation are:

  • OpenAPI (Swagger): a standard for describing REST APIs, which allows documentation and client code generation.
  • JSON Schema: defines the structure of JSON objects used in requests and responses.
  • gRPC (although not REST, but sometimes used as an API contract): a protocol with a protobuf-based contract.

In the context of REST API, OpenAPI is most commonly used, describing:

  • Endpoints (paths and HTTP methods)
  • Request and response formats
  • Parameters and headers
  • Response codes

Example of a simple OpenAPI fragment:

paths:
  /users:
    get:
      summary: Get list of users
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/User'