# REST API

> The most common style of web API: things have URLs and you act on them with HTTP verbs.

- Level: Intermediate
- Topics: Software
- URL: https://tidbit.legios.com.ar/rest-api/
- In Spanish: [API REST](https://tidbit.legios.com.ar/es/rest-api/)

A **REST API** is an API designed around a simple idea: everything the system knows about is a **resource** with its own URL, and you use the standard verbs of HTTP to act on it. `GET /orders/42` reads order 42, `POST /orders` creates a new one, `PUT /orders/42` replaces it and `DELETE /orders/42` removes it. The answer usually comes back as JSON.

The style was described by Roy Fielding in his 2000 doctoral thesis, and the name stands for **REpresentational State Transfer**. One of its rules is that each request is **stateless**: it carries everything the server needs to answer it, so the server does not have to remember previous requests. That makes REST APIs easy to spread over many servers and to cache.

Every answer also brings a **status code**, a three-digit number that says how it went: 200 means OK, 201 created, 404 not found, 401 you are not logged in, 500 the server failed. Because it reuses what the web already has, REST became the default way apps, websites and companies talk to each other. When people say "the Stripe API" or "the GitHub API", they usually mean a REST API.

## An analogy

Like a well-organized library where every book has a fixed shelf address and there are only a few allowed actions: look at it, add one, replace one, remove one. Anyone who knows the rules can find their way around.

## Keep in mind

- Each thing has a URL; the HTTP verb says what to do with it.
- GET reads, POST creates, PUT or PATCH updates, DELETE removes.
- Requests are stateless: each one stands on its own.
- Status codes like 200, 404 and 500 tell you how it went.

## Go deeper

- [What is a RESTful API? (AWS)](https://aws.amazon.com/what-is/restful-api/)
- [REST (MDN glossary)](https://developer.mozilla.org/en-US/docs/Glossary/REST)
- [REST on Wikipedia](https://en.wikipedia.org/wiki/REST)

## Related terms

- [API](https://tidbit.legios.com.ar/api/): The menu of things one program lets another program ask for.
- [URL](https://tidbit.legios.com.ar/url/): The full address of something on the web: protocol, site and path.
- [HTTP](https://tidbit.legios.com.ar/http/): The request-and-response language browsers and websites speak.
- [JSON](https://tidbit.legios.com.ar/json/): The plain-text format programs use to hand each other structured data.
- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
- [Stripe](https://tidbit.legios.com.ar/stripe/): A company that lets websites and apps accept online payments with a few lines of code.
- [GitHub](https://tidbit.legios.com.ar/github/): A website where teams store their code with Git and work on it together.
