# Insomnia: POST

Before you write the POST method, save the request that adds a category in Insomnia, with a JSON body, send it, and learn why the answer today is 405 Method Not Allowed instead of 404.

Journeyman · Spring Boot · REST API · Updated November 16, 2026

By Gregor Dzierzon

## After this lesson you can

- Send a POST request with a JSON body to a Spring Boot API from Insomnia
- Tell 405 Method Not Allowed from 404 Not Found in a Spring Boot API

## Key takeaways

- A POST sends data in a body. In Insomnia, choose JSON on the Body tab and type the new item; Insomnia adds the Content-Type header for you.
- 405 Method Not Allowed means the address exists, but nothing there answers that method. 404 Not Found means nothing answers at the address at all.
- The answer you want from a POST is 201 Created, with the saved item and its new id in the body.
- Every successful send of a POST adds another item, so expect a new id each time.

Your API can read categories. Next it will add them. As before, start by writing down what you want it to answer, as a request in your `Northwind API` collection.

A `GET` asks for something. A `POST` *brings* something: the new category, in the request's **body**. Think of it as the difference between asking a shop what's on the shelf and handing over a box to put on it.

## A request with a body

In Insomnia, add a request to the `Northwind API` collection, name it `Add Snacks`, and set it to:

```text
POST {{ _.base_url }}/api/categories
```

Then give it a body:

1. Open the **Body** tab, under the address bar, and choose **JSON**.
2. Type the new category:

```json
{
  "categoryName": "Snacks",
  "description": "Chips, nuts and pretzels"
}
```

Choosing **JSON** also adds a **header** to the request, `Content-Type: application/json`, which tells the API what kind of body is coming. Open the **Headers** tab to see it. You don't type it yourself.

There's no `categoryId` in the body. The database chooses the new id, so the client doesn't send one.

## 405, not 404

Run your app, and send `Add Snacks`. The answer is `405 Method Not Allowed`.

Why not `404 Not Found`, as `All categories` answered before you wrote its method? Because the address isn't the problem. `/api/categories` exists now: `All categories` gets an answer from it. What's missing is a method that answers **POST** there.

| Status | Means |
|---|---|
| `404 Not Found` | Nothing answers at this address, whatever the method |
| `405 Method Not Allowed` | Something answers at this address, but not to this method |

The answer's **Headers** tab shows which methods the address does accept: `Allow: GET`.

## The answer you want

Once the next lesson is built, `Add Snacks` should answer `201 Created`, which means *"saved, and here it is"*, with the saved category in the body, now with the id the database gave it:

```json
{
  "categoryId": 10,
  "categoryName": "Snacks",
  "description": "Chips, nuts and pretzels"
}
```

Each successful send adds another Snacks, with a new id: 10, then 11, then 12. That's what a POST does. If you send it a few times while you test, the extras are harmless in your own database. Send `All categories` afterwards, and the new categories are at the end of the list.

## Do it: tell 404 from 405

Before you write a method, its request in Insomnia answers `404 Not Found` or `405 Method Not Allowed`, and the difference tells you what's missing. Write a method that works out which, from the list of what the API answers today.

The method gets three values:

- `endpoints`: what the API answers today, a `List<String>`. Each one is a method, a space, and an address, such as `"GET /api/categories"`.
- `method`: the request's method, a `String`, such as `"POST"`.
- `address`: the request's address, a `String`, such as `"/api/categories"`.

For example, after the *GET* lesson, the API answers one endpoint, and you send `Add Snacks`, a `POST` to `/api/categories`:

```java
List<String> endpoints = List.of("GET /api/categories");
```

| Question | For `POST /api/categories` |
|---|---|
| Does an endpoint have this method **and** this address? | no |
| Does an endpoint have this address, with another method? | yes: `GET /api/categories` |
| The answer | `"405 Method Not Allowed"` |

So `check(endpoints, "POST", "/api/categories")` returns `"405 Method Not Allowed"`.

**Your job:** write the method `check(List<String> endpoints, String method, String address)` so it returns a `String`.

- When an endpoint has this method and this address, return `"a method answers"`.
- Otherwise, when an endpoint has this address with another method, return `"405 Method Not Allowed"`.
- Otherwise, return `"404 Not Found"`: nothing answers at this address. That includes an API with no endpoints yet.

Practiced live on the lesson page: write the Java right there and check it.

## Check yourself

2 questions to try on the lesson page.

## So what

A new to-do item in your collection, with a body this time. In the next lesson you write the POST method, and send `Add Snacks` again until it answers `201 Created`.

## Key terms

- [Request Body](https://www.ask-codey.com/glossary/request-body-web-development)
- [Content-Type](https://www.ask-codey.com/glossary/content-type)

## Cheat sheets

- [Insomnia: POST](https://www.ask-codey.com/cheat-sheets/restful-web-apis-insomnia-post-cheat-sheet)

Source: https://www.ask-codey.com/lessons/restful-web-apis-insomnia-post
