> For the complete documentation index, see [llms.txt](https://program.hackyourfuture.dk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://program.hackyourfuture.dk/course-content/backend/node/week2/session-materials/openapi-basics.md).

# 7. OpenAPI Basics

This file supports the OpenAPI/Swagger segment of Week 2.

## Explain the role of OpenAPI

* OpenAPI is a **contract** for your HTTP API.
* It describes:
  * Which paths and methods exist.
  * What parameters and request bodies they accept.
  * What responses (status codes and schemas) they return.
* Tools can use it to:
  * Generate documentation.
  * Generate client/server code.
  * Validate requests and responses.

## Minimal example for `GET /api/snippets`

Use a concise YAML snippet in the session:

```yaml
paths:
  /api/snippets:
    get:
      summary: List public code snippets
      responses:
        "200":
          description: List of snippets
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Snippet"
        "500":
          description: Server error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

components:
  schemas:
    Snippet:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
        contents:
          type: string
    Error:
      type: object
      properties:
        error:
          type: string
```

You do not have to cover the full specification. Focus on:

* Paths and operations.
* Response status codes and bodies.
* A shared `Error` schema that matches what trainees implement in code.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://program.hackyourfuture.dk/course-content/backend/node/week2/session-materials/openapi-basics.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
