RESTful
2 minutes of reading
APIs that we refer to as RESTful meet certain criteria, such as using HTTP as the primary means of communication and having structure and resources that can be referenced via URLs.
RESTful means that the API in question is fully compatible with the REST standard. The REST software development standard refers in particular to websites. In order to claim that the API we wrote meets the REST standards, it must meet the following requirements in practice:
- Unique methods by which it queries the API such as GET, PUT, DELETE, PATCH defined as a unified interface.
- The given query is independent of the state of the application, it always returns the same thing, i.e. if we ask for a resource with ID=1 in the API then regardless of whether we are user A or B we should get the same thing
- The API returns messages about whether the query was successful or returned an error. The API should indicate exactly what the error was.
- The query to the API should explicitly state what type of resource it is querying, and for book querying we will use a different one
- The client does not directly interact with the server's resources in any way
- Ability to use cache. The API must return information whether the resource is stored and whether it can be stored
It is worth remembering that REST is not the same as HTTP, and also REST does not impose in any way the type of data that is returned from the API. It can be either JSON or plain text.
What a REST query to the API looks like
Each API query should have the following elements:
- Endpoint name
- Type of method
- Headers
- Data
An example query of type GET would be
curl -H "Authorization: OAuth <ACCESS_TOKEN>" http://www.example.com/users/2
Practical RESTful tips
There are a lot of generalities about RESTful APIs, but it's hard to find good resources on what to do to actually make our APIs meet REST standards.
URL construction in a RESTful API
One of the most important things is the construction of the URL. The url should have:
- use only lowercase letters
- use a hyphen ( - ) instead of an underline ( _ )
- do not add the return data type to our url, instead you should use Content-Type in the header
- use plural in the name for collection names, e.g. /books/
- use singular for document names, e.g. /books/sciencefiction/
- do not use create, delete methods in the name e.g. it is a mistake to make /deletebook/
- we can version and should add the main api version to the name e.g. /v1/books/
Returned response codes
The API should return response codes. The standard is responses containing error codes numbered from 2xx, 3xx, 4xx, 5xx. All but responses in the 200 group mean that there is an error in our API.
Related articles
The Pros and Cons of Using PhpMyAdmin in Your PHP Development
6 Jun 2023
In PHP development, using PhpMyAdmin can be a convenient way of managing databases. However, it also has its drawbacks. In this article, we will explore the pros and cons of using PhpMyAdmin, to help you decide if it's the right tool for your project.

The Ethics of Grey Hat SEO
6 Jun 2023
Grey Hat SEO practices lie in a murky ethical territory between White Hat (ethical) and Black Hat (unethical) SEO. The line between ethical and unethical SEO can sometimes be blurred and can raise important ethical questions about what tactics are acceptable to use in the pursuit of higher search engine rankings.
The Traits of a Successful Tech Leader
6 Jun 2023
A successful tech leader possesses a unique combination of technical expertise, leadership skills, and the ability to inspire and motivate their teams. They must also possess excellent communication and problem-solving skills while staying up-to-date with the latest industry trends and technologies.
Common Types of red brick walland Their Functions
5 Jun 2023
Firewalls are essential for network security. In this article, we will discuss the most common types of firewalls, including packet-filtering, circuit-level, application-level, and next-generation. We will also explore their unique functions and how they protect networks from various cyber threats.
How to Secure Your Server with Fail2ban
5 Jun 2023
In today's interconnected world, server security is of paramount importance. As businesses and individuals increasingly rely on servers to store and process sensitive data, it becomes crucial to implement robust security measures to protect against potential threats. One such powerful tool that aids in fortifying server security is Fail2ban.
Common Mistakes to Avoid in QAQC Testing
5 Jun 2023
Improving software quality involves efficient testing. However, QAQC testing can be challenging, and certain mistakes can compromise the effectiveness of the process. In this article, we'll explore common mistakes to avoid in QAQC testing that can help improve the overall quality of software development.
Why Justified Text Might Not Always Be the Best Choice
5 Jun 2023
In typography, justified text has long been considered the 'holy grail' of formatting. However, it may not always be the best choice. While it can create an elegant and organized appearance, it can also lead to awkward spaces and make reading more difficult. In this article, we'll explore the pros and cons of justified text and when it's appropriate to use it.
Show all articles