What Else is in Server Software?
We looked at how server sends static content to the browser, and all the magic related to that is performed in the browser.
But the JavaScript also makes some requests to the server to populate the page, and that contains some server-side magic.
REST API
API stands for Application Programming Interface. It is how Software A can utilize the functionality of Software B. The developers of Software B, after coding all the magic they want it to perform, also implement some interfaces. These interfaces are intended to make it easy for Software A to offload some processing to Software B.
REST stands for REpresentational State Transfer. It is the standard API format for two pieces of software to communicate over the internet. Software B, in this case, would be a server software, called a server for short in this context. Software A could be your browser, but it could also be any other app that just uses APIs from a small set of servers. In this context, Software A is called a client.
Every time the client wants some processing to be done by Software A, it has to send some data (called a request), and wait to receive the processed data (called the response). This whole process is called an API call.
The structures of requests and responses are very similar. They both contain:
- Headers, which often contain data that is not needed by the receiver for its main job, but is useful for establishing context, either for interpreting the body or if something goes wrong
- Body, which contains the data that was sent
The request contains some extra information:
- URL, which is just the link to the specific function on the server that the client wants to use
- Queries, which are technically part of the URL but are instead interpreted by the server as input data
- Method, which clarifies the type of action that is to be taken. The most common methods are POST (where data is sent with no reference to existing data on the server, and some response data may or may not be sent back), GET (where existing data is requested from the server), PATCH (where data is sent with some reference to existing data, expecting that it will be updated), and DELETE (where a reference to existing data is sent with the expectation that it will be deleted from the server). These methods are customary and not enforced strictly, so API documentation needs to be clear about it.
- Authentication headers, which are parts of a header used to establish identity and permission.
The response also contains a status code, the most common of which is "200 OK" but the most well known is "404 Not Found".
Database
A database is a piece of software which stores data in such a way that reading and writing is very efficient. This data is often limited to text, numbers, and date. Some extra data types are sometimes provided, but they are often simple extensions of the pre-existing data types.
Other complicated types of data (such as files) are stored in bulk storage, with some of their metadata and their location stored in the database for easy lookup.
Most databases are setup to store their files in a dedicated folder, and access to the database is through an API. Some databases just store data in a file and leave the reading and writing up to the software that accesses it.
Relational Databases
These store data in tables, with entries in some columns referring to rows in another table. These relations can get quite messy for complex data storage. Structured Query Language or SQL is a language that is used toaccess data in relational databases.
Key-Value Databases
These store data in "documents", where a document is just a list of labels (known as keys), and some data associated with that label (known as values). A value can be an entire document by itself, creating a structure not unlike folders and files in a computer.