Dear Diary, Crud my life#308

Can you explain the purpose of each type of HTTP Request when using a RESTful web service?

— The verbs usually coincide with the well known CRUD functions. Create, Read, Update, Delete.

The purpose of each of the HTTP request types, when used with a RESTful web service, is as follows:

GET (read)

Retrieves data from the server (should only retrieve data and should have no other effect). This is also called an idempotent method. here is an example of a GET request to retrieve the book with id 123 from Server.

POST (create)

This HTTP request type is usually used for creating an entity i.e. a resource without an id. Once the request is successfully created, an id of the newly created entity is returned as part of the response to this HTTP request. It is often used when uploading a file or submitting a completed web form.

For example, following URL will create a new book in the server

PUT (update)

Similar to POST, but used to update an existing entity. You pass the id of existing resource along with PUT request type. For example, following URL will replace the book with id 123 in the server

DELETE (delete)

Removes the resource from the server. Similar to PUT you need to pass the id of the resource to be deleted. For example, following URL will remove the book with id 123 in the server

What’s a test pyramid? How can you implement it when talking about HTTP APIs?

— The “Test Pyramid” is a metaphor that tells us to group software tests into buckets of different granularity. It also gives an idea of how many tests we should have in each of these groups. Although the concept of the Test Pyramid has been around for a while, teams still struggle to put it into practice properly. This article revisits the original concept of the Test Pyramid and shows how you can put this into practice. It shows which kinds of tests you should be looking for in the different levels of the pyramid and gives practical examples on how these can be implemented.

When talking about HTTP APIs, it may come down to this:

  • a lot of low-level unit tests for your models
  • less integration tests, where your test how your models interact with each other
  • a lot less acceptance tests, where you test the actual HTTP endpoints

So the importance of API testing is obvious. Several methods and resources help with HOW to test APIs — manual testing, automated testing, test environments, tools, libraries, and frameworks. However, regardless of what you will use — Postman, supertest, pytest, JMeter, mocha, Jasmine, RestAssured, or any other tools of the trade — before coming up with any test method you need to determine what to test

What is the “demultiplexer”?

— A demultiplexer (or demux) is a device that takes a single input line and routes it to one of several digital output lines. A demultiplexer of 2 n outputs has n select lines, which are used to select which output line to send the input. A demultiplexer is also called a data distributor.

What’s the difference between “blocking” and ‘non-blocking’ functions?

— Blocking call: Control returns only when the call completes.

— Non blocking call: Control returns immediately. Later OS somehow notifies the process that the call is complete.

— Synchronous program: A program which uses Blocking calls. In order not to freeze during the call it must have 2 or more threads (that’s why it’s call Synchronous — threads are running synchronously).

— Asynchronous program: A program which uses Non blocking calls. It can have only 1 thread and still remain interactive.

— The intention is to allow the program to not be blocked waiting for a slow process to complete — how the program is expected to respond is the only real difference. Which term refers to which also changes from programmer to programmer, language to language, or platform to platform. Or the terms may refer to completely different concepts (such as the use of synchronous/asynchronous in relation to thread programming).

What are the main security implementations within NodeJS?

— The main ones include (but are not limited to) authentications and error handling. These are the two methods most commonly associated with security management within Node JS — and they do seem to work well!

Explain the “path” module in NodeJS.

— The path module provides a lot of very useful functionality to access and interact with the file system.

— There is no need to install it. Being part of the Node core, it can be used by requiring it:

— These are the path methods:

Austin Coding Academy