HTTP Requests

Hong Ly
6 min readJan 16, 2021

HyperText Transfer Protocol (HTTP) is the underlying protocol that is used by World Wide Web (WWW) and it is a protocol defines how messages are transmitted, formatted, and what actions web browsers and servers should get in response to different commands [1]. HTTP is designed to enable communications between clients and servers. Two commonly used methods for a request-response between a client and server are: GET and POST [2].

GET — Requests data from a specified resource.

POST — Submits data to be processed to a specified resource.

Send Data with POST Requests in Ionic

Post requests code in Ionic [3]

Get Data with Get Requests in Ionic

Get requests code in Ionic [5]

In Firebase, only authenticated users are allowed to read and write data. Therefore, we need to get the token and send it with HTTP request to confirm to firebase to the backend that the user is allowed to read or write so that the user is authenticated.

URL to access Firebase by HTTP requests
storePost method with post request

URI Component Encoding

The encodeURIComponent() is a function used to encode a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character [4].

encodeURIComponent vs. encodeURI [4]

Three Common HTTP Codes

When surfing on the Internet, it works on a request-response system. When we type a URL after http: in the browser’s address bar to request a web page or an image, we will get a response. As defined by HTTP, status code is an important part of its structure.

404 Not Found

One of the most common error code you would run into is a 404 error. The 404 status code refers to the requested resource is no longer available or it is just not found. A missing or extra letter in a typed-in url which is not existed or a wrong domain name can also result in a 404 error [6].

403 Forbidden

Another common error code from client-side response status code is 403. Retrieving a 403 status code from an HTTP request means accessing to the resource is forbidden. This is not because of an authentication problem [6]. Those are 401 (unauthorized) errors. One common reason for 403 errors is the server maintaining a whitelist of machines that can access that system while the user’s computer not being on it.

503 Service Unavailable

The 503 status code could be a temporary problem, indicating service unavailable. It means the web server isn’t available. The problem can be caused by the web server is just restarted and is in the process of initialization. Or it is overloaded and can’t handle any more concurrent requests. Or it is just down for maintenance [6].

Types of Data Stored on a Server per User

There are many types of data that can be stored on a server for each particular user. That includes as follows:

Email account: username and password

Bank detail

Address

Date of birth

ID

Driver license

These types of data are unique to each specific user and it is securely stored on the server to avoid being hacked.

Types of Data Stored on a Server for All Users

Data stored on a server that is made available for all users, mostly contains general detail that all users might find useful and that could be:

Cloud Deakin: Consists of weekly resources or Blackboard collaboration that is accessible from all current students.

Online Shop: Amazon or eBay

http://www.australia.gov.au/ (General information about Australian government services)

Character Encoding

A character encoding tells a computer how to interpret raw zeroes and ones into real characters. Generally, it does this by pairing numbers with characters.

ASCII is the first character encoding standard (character set). It defines 128 different alphanumeric characters that is used on the Internet, containing numbers, English letters and some special characters [8].

ANSI (Windows-1252) was the original Windows character set, supporting 256 different character codes.

ISO-8859–1 was the default character set for HTML 4. This character set also supported 256 different character codes.

Unicode is a standard which defines the internal text coding system in almost all operating systems including Windows, UNIX, Macintosh, Linux and more. Unicode can handle characters for almost all modern languages and even some ancient languages.

Unicode assigns each character a unique number, or code point. It consists of two mapping methods, the UTF (Unicode Transformation Format) encodings, and the UCS (Universal Character Set) encodings. Unicode-based encodings apply the Unicode standard and include UTF-8, UTF-16 and UTF-32/UCS-4. These types of Unicode go beyond 8-bits and support almost every language in the world [9].

Because ANSI and ISO-8859–1 were so limited, HTML 4 also supported UTF-8.

UTF-8 (Unicode) covers almost all of the characters and symbols in the world.

The differences between character encoding and font is that a font is a file that contains glyphs ordered according to some numbering scheme which is not the same as the numbering in any character sets. Before there were bit-mapped fonts which represented a specific size either in pixels or points of a typeface. Currently, most fonts use mathematical curves to describe glyphs and it can be scaled to represent any size of typeface.

UTF-8 uses 1 byte to represent characters in the ASCII set, 2 bytes for characters in several more alphabetic blocks, and 3 bytes for the rest of the BMP. Supplementary characters use 4 bytes [9].

UTF-16 uses 2 bytes for any character in the BMP, and 4 bytes for supplementary characters.

UTF-32 uses 4 bytes for all characters.

For Ionic applications, UTF-8 would be the best choice to use as the default character encoding since it covers almost all of the characters and symbols in the world.

References

[1] “What is HTTP — HyperText Transfer Protocol? Webopedia Definition”, Webopedia.com, 2017. [Online]. Available: http://www.webopedia.com/TERM/H/HTTP.html. [Accessed: 9- Sep- 2017].

[2] “HTTP Methods GET vs POST”, W3schools.com, 2017. [Online]. Available: https://www.w3schools.com/tags/ref_httpmethods.asp. [Accessed: 09- Sep- 2017].

[3] J. Morony, “How to Send Data with POST Requests in Ionic 2”, joshmorony — Build Mobile Apps with HTML5, 2017. [Online]. Available: https://www.joshmorony.com/how-to-send-data-with-post-requests-in-ionic-2/. [Accessed: 10- Sep- 2017].

[4] “encodeURIComponent()”, Mozilla Developer Network, 2017. [Online]. Available: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent. [Accessed: 12- Sep- 2017].

[5] J. Morony, “Using Http to Fetch Remote Data from a Server in Ionic 2 & 3”, joshmorony — Build Mobile Apps with HTML5, 2017. [Online]. Available: https://www.joshmorony.com/using-http-to-fetch-remote-data-from-a-server-in-ionic-2/. [Accessed: 13- Sep- 2017].

[6] L. Center, “5 Most Common HTTP Error Codes Explained — Globo.Tech”, Globo.Tech, 2017. [Online]. Available: https://www.globo.tech/learning-center/5-most-common-http-error-codes-explained/. [Accessed: 13- Sep- 2017].

[7] “Microservices Pattern: Database per service”, microservices.io, 2017. [Online]. Available: http://microservices.io/patterns/data/database-per-service.html. [Accessed: 14- Sep- 2017].

[8] “HTML Charset”, W3schools.com, 2017. [Online]. Available: https://www.w3schools.com/html/html_charset.asp. [Accessed: 13- Sep- 2017].

[9] Net-informations.com. (2017). What is character encoding. [online] Available at: http://net-informations.com/q/faq/encoding.html [Accessed 15 Sep. 2017].

--

--