Unnderstanding REST APIs
REST stands for REPRESENTATIONAL STATE TRANSFER. It is an architecture style for designing networked applications. It works by relying on a stateless, client-server communication protocol which in almost all cases is the HTTP.
REST was made to treat objects on the server side as resources that can be created, updated and destroyed and of course read. Example of this, is a blogpost, and it is usually stored in a database. We can create request with the 'POST' request, also delete with the 'DELETE' request.
What makes REST awsome is that it can be used virtually by any programming language like Javascript, php, Ruby and Rails, Java, Python and so on. All these languages are capable of working with REST APIs.
NOTE: The API is the messenger and then REST helps us to use the HTTP request to format that message.
REST APIs takes in multiple types of HTTP request.
TYPES OF HTTP REQUESTS
GET: Retrievs data from a specified resource
POST: this is usually used to submit data to be processed to a specific resource. i.e to add a post to a database or to add a user account.
PUT: This is used to update a specific ressource already on the server.
DELETE: This is ofcourse used to delete a specified resource on the server.
other types of HTTP Requests
HEAD: Same as 'GET' but does not return a body
OPTION: Returns the supported HTTP methods of a specific server or API
PATCH: Update partial resources. It is similar to 'PUT'
API ENDpoints
When using some APIs [self created or external] you are going to have something called 'ENDpoints'.
// this serves as comments
GET someurl.com/api/users // Get all users
GET someurl.com/api/users/1 // Get single users
POST someurl.com/api/users // Add users
PUT someurl.com/api/users/1 // Update user
DELETE someurl.com/api/users/1 // Delete user
NOTE: It's completely up to the APIs how they want to format the URLs and the number '1' is an id passed unto the url. It's not conistant but varies.
Credits: Brad Traversy aka Traversy Media.