AI Hints
Home›Spring Boot Tutorial›What REST Is, Returning Objects as JSON and Records for Data
Spring Boot · Lesson 19 of 120

What REST Is

A style for APIs.

⏱ 2 min read▶ Video at 25:04🎓 Free
Watch this lesson in the Spring Boot courseWatch on YouTube ↗Full Spring Boot course

Most web APIs follow a style called REST. It's not a library. It's a set of simple rules, for how URLs and methods should look.

  • A style, not a library
  • Simple rules
  • URLs and methods

The main ideas

Everything is a resource, a thing with a name, like books, or authors. Each resource has a URL, made of nouns, like slash books. The HTTP method says what to do with it. And the data travels as JSON.

keyvalue
Resourcea thing: books, authors
URLnouns: /books, /books/3
Methodthe verb: GET, POST ...
DataJSON

A REST API for books

Here is the classic pattern. GET slash books lists all books. GET slash books slash three gets one book. POST slash books creates a new book. PUT slash books slash three replaces book three. And DELETE slash books slash three removes it.

RequestMeaning
GET /bookslist all books
GET /books/3get book 3
POST /bookscreate a book
PUT /books/3replace book 3
DELETE /books/3delete book 3

Verbs in URLs

A common mistake is putting verbs in the URL, like slash get books, or slash delete book. In REST, the URL names the thing, and the HTTP method is the verb. That keeps every API predictable.

Not REST

  • /getBooks/deleteBook?id=3/createNewBook

REST

  • GET /booksDELETE /books/3POST /books

Summary

REST uses noun URLs for resources, HTTP methods as verbs, and JSON for data. Next, returning objects as JSON.

Key takeaways
  • Resources and URLs
  • Methods are verbs
  • JSON data
Next up: Returning Objects as JSON — from Java to JSON