# GET

Handle a GET request in Spring Boot with @GetMapping, return the categories as JSON, and check it from Insomnia.

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

By Gregor Dzierzon

Requesting data from a REST API is done through a `GET` request.

![A GET request is a header only: the verb GET and an address such as http://localhost:8080/categories, /categories?name=Sports or /categories/10](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/09/72c2b0e1db12474e8c44ac67e6bc53fa.png "A GET request is a header only: the verb GET and an address such as http://localhost:8080/categories, /categories?name=Sports or /categories/10")

The server retrieves and returns the data.

![The server answers with status 200 (success) and a body holding the categories as a JSON array](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/09/20aadf0e559c4214a6b199fa782d70c4.png "The server answers with status 200 (success) and a body holding the categories as a JSON array")

## GET Request - Client

In Insomnia, this is your `All categories` request from *Insomnia: GET*:

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

## GET Request - Server

When a client makes a request, the server directs it to a controller. The method that handles the request must be marked with the `@GetMapping` annotation. Add this method to your `CategoriesController`:

```java
@GetMapping(path="/api/categories")
public List<Category> getAllCategories ()
{
  //use the DAO to get all categories
  return categoryDao.getAllCategories();
}
```

## GET Response - Client

Run the app again in IntelliJ, and send `All categories` from Insomnia. The `404 Not Found` from *Insomnia: GET* is now `200 OK`, with every category as a JSON array: the answer you wrote down.

![Insomnia shows 200 OK and a JSON array of categories, starting with Beverages and Condiments](https://www.ask-codey.com/lessons/TODO)

## Do it: search the categories by name

The first picture above shows one more kind of GET: `/categories?name=Sports`, which asks only for the categories with *Sports* in their name. Spring Boot can hand the controller that `name` from the address; the real work is the filtering. Write that part as a method of its own.

`Category` is given at the bottom of the file, with `getCategoryId()` and `getCategoryName()`.

The method gets two values:

- `categories`: every category, a `List<Category>`.
- `name`: the text from `?name=` in the address, a `String`. It's `null` when the address has no `?name=`.

The tests use Northwind's eight categories. For example, `GET /api/categories?name=con`:

| Category | Has *con* in its name, capitals or not? |
|---|---|
| Beverages | no |
| **Condiments** | **yes** |
| **Confections** | **yes** |
| Dairy Products | no |
| Grains/Cereals | no |
| Meat/Poultry | no |
| Produce | no |
| Seafood | no |

So `search(categories, "con")` returns the two categories Condiments and Confections, in that order.

**Your job:** write the method `search(List<Category> categories, String name)` so it returns a `List<Category>`.

- When `name` is `null`, return every category.
- Otherwise, return the categories whose name contains the text, ignoring capitals: `"SEA"` finds *Seafood*.
- Keep them in the order they're in the list.
- When no name matches, return an empty list.

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

## Cheat sheets

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

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