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