REST is acronym for REpresentational State Transfer. REST API is an application which communicates with the clients using HTTP-protocol. The client can be a web-application, or Mobile application or any application which is able to use http. The REST API will handle the connection to the database.
REST allows different messaging formats, such as HTML, JSON, and XML. This tutorial is focused on JSON (JavaScript Object Notation).
REST API uses HTTP requests to GET, PUT, POST and DELETE data.
You can read more about it from:
Can we use MVC in REST API? Yes, partly. We can implement the Model and the Controller to the REST API and then the View-part will be a separate application. The View can be a mobile application, or a web-application, or a desktop-application.
Within computer programming, the acronym CRUD stands for create, read, update and delete.
The acronym CRUD refers to the major operations which are implemented by databases. Each letter in the acronym can be mapped to a standard Structured Query Language (SQL) statement.
CRUD | SQL |
---|---|
Create | INSERT |
Read | SELECT |
Update | UPDATE |
Delete | DELETE |
HTTP(Hypertext Transfer Protocol) is a protocol which is used to transfer files over the ip-network. You can read more about http from https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview.
HTTP messages means the data that is exchanged between a server and a client. There are two types of messages:
Http message includes allways headers and it can also include a body. You can find a list of http headers from https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers.
In REST API we can use these HTTP methods:
When you are using GET and DELETE you can add data only inside header. When you are using POST you can add data only inside body. When you are using POST you can add data to header and to body.
Example if you want to send a variable named fname, with a value Jim using GET-method, then the url will be something like
http://localhost/api/?fname='Jim'
But if you are using POST-method then, the url is just like this
http://localhost/api
When we are using DELETE, we will add the id to the url on the same way as in GET-method. And when we are using PUT, we will add the id to the url and the update data to the body.
A common way to build a REST API is that, you don't have to include the variable names in your GET-requests. So that instead of this kind of url
http://localhost/api/?id=5
you can just type http://localhost/api/5
You can read more about those methods from:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
http://www.restapitutorial.com/lessons/httpmethods.html
The http response includes status code, which gives information about the response. The most important classes of the codes are:
You can read about the status codes from:
https://www.restapitutorial.com/httpstatuscodes.html
HTTPS(Hypertext Transfer Protocol Secure) is an extension for the HTTP. If you use HTTP, all the information will be transfered in plain text format. But if you use HTTPS, the information will be encrypted.
JSON objects are written inside curly brackets. Example like this
{ "id_book": 11, "name": "javascript", "author": "Mike Jones", "isbn": "9780030604577" }
JSON arrays are written inside square brackets. The array can contain several objects. Like this
[ { "id_book": 11, "name": "New Book", "author": "Mike", "isbn": "22" }, { "id_book": 7, "name": "Signal Slot", "author": "Jim Bim", "isbn": "2345-66" } ]
CORS allows web applications from one domain to access resources from another domain. Without CORS, browsers restrict cross-origin HTTP requests initiated by scripts, which could prevent your API from being accessed by clients running on different domains.
Authentication and authorization are two vital information security processes that administrators use to protect systems and information. Authentication verifies the identity of a user or service, and authorization determines their access rights.
The purpose of authentication is to verify that someone or something is who or what they claim to be.
Authorization is the security process that determines a user or service's level of access. In technology, we use authorization to give users or services permission to access some data or perform a particular action.
In the context of an HTTP transaction, basic access authentication is a method for an HTTP user agent (e.g. a web browser) to provide a username and password when making a request. In basic HTTP authentication, a request contains a header field in the form of Authorization: Basic <credentials>, where credentials is the Base64 encoding of ID and password joined by a single colon.
JWTs or JSON Web Tokens are most commonly used to identify an authenticated user. JWT authentication follows a 4 step process: