What is RESTful API Architecture?

REST stands for Representational State Transfer.

It’s a way for computers to talk to each other over the internet, usually between a frontend (like a website or app) and a backend (like a server or database).

A good way to think about it is a set of rules, “If you want to get, create, update, or delete something on a backend system, here’s how you should ask for it.”.

Those “somethings” are called resources — like users, products, posts, or orders.

Example:

A common example is an API for an E-commerce website.

Let's imagine we are creating an online shoe shop.

Our backend database will store information about the shoes we sell. We could create a REST API that works something like this:

ActionHTTP MethodURL ExamplePurpose
Get all shoesGET/shoesReturns a list of all stored shoes
Get one shoeGET/shoes/123Returns the info of shoe with ID 123
Add a shoePOST/shoesAdds a new shoe (you would provide info in the request body)
Update a shoePUT/shoes/123Updates the info of the shoe with ID 123 (include updated info in request)
Delete a shoeDELETE/shoes/123Deletes the shoe with ID 123

An example URL could look something like this:

GET https://api.myshoeshop.com/shoes/123

With an example response:

{
    "id": 123,
    "name": "Running Shoes",
    "size": 10,
    "colour": "black"
}

Key Traits of REST APIs

REST Alternatives

Listed below are some alternatives to the REST API architecture.

GraphQL

GraphQL is a query language for APIs that Facebook created.

It lets a client, like a web or mobile app, ask for exactly the data it needs.

Unlike REST, where you get a fixed response from each endpoint, GraphQL lets you customise the shape of the data in a single request.

For example using REST:

GET https://api.myshoeshop.com/shoes/123

May return all the information about a shoe:

{
    "id": 123,
    "name": "Running Shoes",
    "size": 10,
    "colour": "black",
    "stock" : 100,
    "discount": "10%"  
}

However, with GraphQL we could just get the ID and name from the shoe

{
  shoe(id: 123) {
    id
    name
  }
}

Specific data returned:

{
  "data": {
    "shoe": {
      "id": "123",
      "name": "Running Shoes"
    }
  }
}

GraphQL can be useful if your client needs different data combinations from the same resources or if you want to minimise data transfer.

Pros:

Cons:

gRPC

gRPC stands for Google Remote Procedure Call. It is an efficient, high-performance communication protocol that uses binary data (Protocol Buffers) instead of JSON or XML.

It’s designed for service-to-service communication such as microservices talking to each other inside a backend system.

You define services using .proto files. Then both the client and server generate code from these files to communicate efficiently.

gRPC can be used when:

Pros:

Cons:

WebSockets

WebSockets let the client and server keep an open two-way connection to communicate between.
Unlike REST or GraphQL (where the client must ask each time), WebSockets allow real-time updates allowing the server to send new data to the client the moment something changes.

WebSockets are often used when:

Pros:

Cons:

SOAP

SOAP or Simple Object Access Protocol is an older XML-based protocol for APIs.
It defines strict rules about message structure and relies on XML envelopes.
It’s often used in enterprise or legacy systems such as banking, insurance, or government software.

It's mainly used when:

Pros:

Cons:

Build a RESFful API

This was a guide to what a REST API is, how it's used and some alternatives to REST.

If you're interested in building your own REST API with Java/Spring, see: Build your first REST API with Spring Boot and Java