TRANSFER DATA BETWEEN NODEMCU AND WEB BROWSER


 Answer is HTTP.

What is HTTP?

HTTP stands for Hyper-Text Transfer Protocol. Quite a mouthful isn’t it? Let’s break this down word for word.

Let’s start with Protocol. If you’ve ever been to an official event, or you’ve ever interacted with a police officer, you would’ve heard the phrase “following protocol”. A protocol is simply a set of rules to be followed in particular circumstances.

For example, if the leader of your nation decides to visit a school in a village, his/her managers and event organizers make sure a particular safety protocol is followed in and around the school area. This means that all the people in the vicinity of the school have to follow a set of rules which are intended to provide security to the leader.

Now let’s talk about Hyper-Text. Data on the internet is usually transferred between systems in Hypertext format. Hypertext means that it is more than just plain text. It contains information which is valuable to the owners of the data. Hypertext can be used to link to external web pages, it can be used to send commands, it can read and write data to a database, and so much more.

To summarize, HTTP basically lists a set of rules which need to be followed when Transferring Hyper-Text data over the internet.

When we say that HTTP is being used to transfer data, two parties are involved: one is the called the server, and the other is called the client.

Generally, a client is any computer that requests data from a server, and a server is a computer that provides the requested data to the client.

When sending a request, the concept of URL comes into the picture. URL stands for Uniform Resource Locator. It identifies a piece of data and provides the address(network location) to access it. Any HTTP request is always associated with a URL to some data resource.

There is so much more about HTTP that you can learn, but let’s focus on what we need to get started.

 

HTTP commands

There are several actions that a client could request the server to perform. HTTP gives a few commands that will be used most generally.

These requests are:

  • GET: It is used to read existing data. The request must contain all the necessary information the server needs to locate and return the data.

 

  • POST: It is used to create a new piece of data. POST requests usually carry an additional body message (also called a payload) that specifies the new data.

 

  • PUT: It is used to update existing data. The body message usually contains the data that needs to be updated.

 

  • DELETE: It is used to delete existing data.

 

PUT and DELETE are sometimes considered specialized versions of the POST verb, and they may be packaged as POST requests with the body message containing the exact action: create (POST), update(PUT) or delete(DELETE).

There are some lesser used verbs that HTTP also supports: HEAD, TRACE, and OPTIONS. But these are not important.

 

HTTP Status Codes

When a computer makes a request to a server, the server will always return a 3 digit number, whether it sends data with it or not. This number is called a status code and it tells the computer how the server has reacted to its request.

If this number is in 200s, it means that the server has a positive reaction to the request. The most common positive reactions are

  • 200: successful. This means that the requested action has been successfully completed. Usually, a GET request will return this code.

 

  • 201: created. This means that new data has been created. A POST request will return this code along with an id that indicates the identification number the server has assigned to the new data.

If the code is in the 400s, it depicts a negative reaction. The server thinks the client is at fault here, meaning it has made an error while sending a request. The most common 400 codes are:

 

  • 400: Bad Request. The server thinks that the request sent by the client had errors in terms of its form. This includes wrong syntax, spelling mistakes, etc.

 

  • 401: Unauthorised. This means the client does not have the permission to access the requested data.

 

  • 403: Denied. The server refused to share the requested data to the client.

 

  • 404: Not Found. The requested data was not found in the specified location.

 

  • 405: Method not allowed. The HTTP request used is not supported by the server.

 

  • 409: Conflict. When two or more clients try to update the same resource using PUT and do so at nearly the same time, this error is returned.

No comments:

Post a Comment