> 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
