> 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/rest-principles-snippets.md).

# 6. REST Principles

This file provides mentor-facing notes for the REST design segment of Week 2.

## Core ideas to highlight

* **Resources, not actions**: model the API around nouns like `snippets`, `tags`, and `users`, not verbs, for example: (`getUsers` is a bad practice)
* **Predictable URLs**: use plural resource names and consistent patterns, e.g.:
  * `GET /api/snippets` – list snippets
  * `POST /api/snippets` – create a snippet
  * `GET /api/snippets/:id` – get a single snippet
  * `PUT /api/snippets/:id` – update a snippet
  * `DELETE /api/snippets/:id` – delete a snippet
* **Use HTTP methods meaningfully**: `GET` (read), `POST` (create), `PUT/PATCH` (update), `DELETE` (remove).
* **Statelessness**: each request contains everything needed; server does not store per-client session state (week 3 will introduce authentication trade-offs).

## Relationships and query design

* Snippets can have many tags and belong to a single user.
* Encourage trainees to think about:
  * Whether to expose nested routes (e.g. `GET /api/users/:id/snippets`) vs query parameters (`GET /api/snippets?userId=...`).
  * Potential traps with nesting: (e.g. `GET /api/users/:id/snippets` vs `GET /api/users/:id`)
  * How to design search/filter endpoints using query parameters (e.g. `GET /api/snippets?tag=javascript`).
  * When to add pagination parameters like `limit` and `offset` or `page` and `pageSize`.


---

# 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/rest-principles-snippets.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.
