# REST API

* **Multiple Endpoints**: A REST API usually has different endpoints for different resources (e.g., `/users`, `/orders`).
* **Fixed Data Structure**: The server determines the structure and amount of data returned, which can sometimes result in over-fetching or under-fetching.
* **Predefined Responses**: Each endpoint returns a fixed set of data, and customizing the response requires modifying the endpoint or adding new one
* **Less Flexible**: Clients typically receive a full resource representation, and changes to the data format may require updates to the server or API versioning.
* **Multiple Requests**: Nested or related data often requires multiple API calls, potentially leading to performance inefficiencies.
* **Versioning Required**: REST often uses versioning (e.g., `/api/v1/`) to manage changes and avoid breaking existing clients. This can lead to version sprawl over time.
* **Separate Error Responses**: Errors are usually returned in different HTTP status codes (e.g., `404`, `500`), making it simpler but also less flexible in terms of combining partial data with errors.
* **No Type System**: REST APIs do not inherently include a type system. JSON Schema or similar tools can be used, but they are not part of the REST standard.

#### **REST API Example**

* **Endpoint 1**: `/users/1` (to get user details)
* **Endpoint 2**: `/users/1/posts` (to get the user's posts)

1. **Request 1 (Get user details)**:

```http
GET /users/1
```

**Response**:

```json
{
  "id": 1,
  "name": "John Doe",
  "email": "john.doe@example.com"
}

```

2. **Request 2 (Get user's posts)**:

```http
GET /users/1/posts
```

**Response**:

```json
[
  {
    "postId": 101,
    "title": "My first post",
    "content": "This is the content of my first post."
  },
  {
    "postId": 102,
    "title": "Another day, another post",
    "content": "Here's some more content."
  }
]

```


---

# Agent Instructions: 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:

```
GET https://www.anandisheladiya.com/skills-and-experience/api/rest-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
