DEV Community

JohnDivam - justnote8.com
JohnDivam - justnote8.com

Posted on

RESTful API vs REST API: Is There Actually a Difference?

What is REST?

REST (Representational State Transfer) is an architectural style, not a protocol or a standard. It was introduced by Roy Fielding in his 2000 doctoral dissertation.

REST defines a set of constraints:

  1. Client-server: UI and data storage are separated.
  2. Stateless: each request contains everything the server needs; no session state on the server.
  3. Cacheable: responses declare whether they can be cached.
  4. Uniform interface: resources are identified by URLs and manipulated through standard methods.
  5. Layered system: clients don't know if they talk to the real server or an intermediary.
  6. Code on demand (optional): the server can send executable code to the client.

REST API vs RESTful API

REST API RESTful API
Meaning An API that uses REST ideas An API that faithfully follows REST constraints
Strictness Loose, common usage Strict, by-the-book
Typical in practice JSON over HTTP, resource URLs Same, plus correct verbs, status codes, statelessness, ideally HATEOAS

In other words:

  • REST is the architectural style.
  • REST API is the everyday label for an HTTP API inspired by it.
  • RESTful describes how well an API conforms to that style.

Example: not RESTful

POST /getUser
POST /createUser
POST /deleteUser?id=42
Enter fullscreen mode Exit fullscreen mode

Here HTTP is just a tunnel. The action is in the URL, and every call is a POST. This is closer to RPC than REST.

Example: RESTful

GET    /users        # list users
GET    /users/42     # get one user
POST   /users        # create a user
PUT    /users/42     # replace a user
PATCH  /users/42     # partially update a user
DELETE /users/42     # delete a user
Enter fullscreen mode Exit fullscreen mode

The URL identifies the resource (a noun), and the HTTP method expresses the action.

RESTful in Laravel

Laravel makes this almost free with resource routes:

// routes/api.php
Route::apiResource('users', UserController::class);
Enter fullscreen mode Exit fullscreen mode

This single line generates index, store, show, update, and destroy, mapped to the right verbs and URLs.

And return proper status codes:

public function store(StoreUserRequest $request)
{
    $user = User::create($request->validated());

    return response()->json($user, 201); // 201 Created, not 200
}

public function destroy(User $user)
{
    $user->delete();

    return response()->noContent(); // 204 No Content
}
Enter fullscreen mode Exit fullscreen mode

The HATEOAS Problem

The most-ignored REST constraint is HATEOAS (Hypermedia as the Engine of Application State): responses should include links telling the client what it can do next.

{
  "id": 42,
  "name": "Hakim",
  "_links": {
    "self": { "href": "/users/42" },
    "orders": { "href": "/users/42/orders" },
    "delete": { "href": "/users/42", "method": "DELETE" }
  }
}
Enter fullscreen mode Exit fullscreen mode

Almost nobody implements this, which means that, strictly speaking, most "RESTful" APIs aren't fully RESTful by Fielding's definition. Some people call the pragmatic version "REST-ish" or simply an "HTTP API."

Checklist for a "RESTful enough" API

  • [x] Nouns in URLs, plural (/users, not /getUsers)
  • [x] Correct HTTP verbs for each action
  • [x] Meaningful status codes (201, 204, 404, 422)
  • [x] Stateless requests (token auth, no server sessions)
  • [x] Consistent JSON structure
  • [x] Versioning (/api/v1/...)
  • [ ] HATEOAS (optional in practice)

So which term should you use?

  • In daily conversation, docs, and job descriptions, "REST API" and "RESTful API" mean the same thing. Use either.
  • In a technical discussion, "RESTful" implies you follow the constraints properly.
  • If someone is being strict, the honest answer is: "It's REST-style, but not full HATEOAS."

Conclusion

REST is the style, REST API is the common label, and RESTful means faithful to the style. What matters more than the term is designing APIs that are predictable, stateless, and consistent with HTTP semantics.

How do you use these terms on your team? Does anyone actually implement HATEOAS? Let me know in the comments.


Found this useful? Follow me for more backend and Laravel content.

Top comments (1)

Collapse
 
suppdevbot profile image
DEV SUPPORTS •
You need to verify your account.
Enter fullscreen mode Exit fullscreen mode

tr.ee/dev-to