Skip to content

Commit

Permalink
docs: feedback by Raymond
Browse files Browse the repository at this point in the history
Applied feedback by Raymond.
  • Loading branch information
Yaapa Hage committed Mar 25, 2020
1 parent df3c79d commit d08a704
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions docs/site/Req-res-cycle.md → docs/site/Request-response-cycle.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
lang: en
title: 'Request-response cycle'
title: 'Request/response cycle'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/Application.html
permalink: /doc/en/lb4/request-response-cycle.html
---

## The LoopBack 4 request-response cycle
## The LoopBack 4 request/response cycle

To understand the LoopBack 4 request-response cycle, let's start by enumerating
To understand the LoopBack 4 request/response cycle, let's start by enumerating
the APIs that create the endpoints on the server. We will then follow the path
taken by a request, to see how it makes its way through the various parts of the
framework to return a result.

### Setting up the request-responses infrastruture
### Setting up the request/response infrastruture

The endpoints on a LoopBack app can be categorized into controller endpoints and
non-controller endpoints. Controller endpoints are those that are created by
Expand All @@ -30,7 +30,7 @@ controller method.
{% include tip.html content="Apart from controller files in the `controllers` directory,
controllers may be added to the app by [components](https://loopback.io/doc/en/lb4/Components.html)." %}

In the request-response cycle section we will see how implemenation details
In the request/response cycle section we will see how implemenation details
determine the course of a request to these endpoints - they may or may not actually
interact with a model.

Expand Down Expand Up @@ -71,12 +71,12 @@ units of LoopBack. Since they can access the LoopBack app instance, the request
and response instances using [dependency injection](https://loopback.io/doc/en/lb4/Dependency-injection.html),
they are capable of adding new endpoints and determining the result of a request.

### The request-response cycle
### The request/response cycle

The request-response cycle involves many components, especially if the request
The request/response cycle involves many components, especially if the request
is to a controller-endpoint which interacts with the database.

![Components of LoopBack 4 request-response cycle](./imgs/req-res-high-level.png)
![Components of LoopBack 4 request/response cycle](./imgs/req-res-high-level.png)

The request handling process starts with the app's [sequence](https://loopback.io/doc/en/lb4/Sequence.html);
it is the gatekeeper of all requests to the app. Every request, whether to
Expand All @@ -88,9 +88,9 @@ the response back to the client.

#### The sequence

The sequence is a simple class with five injected helper methods. These five
methods come together in the sequence class to make the request-response cycle
possible in LoopBack.
The sequence is a simple class with five injected helper methods in the
constructor. These five methods come together in the sequence class to make the
request/response cycle possible in LoopBack.

{% include tip.html content="All of the injected helper methods are [providers](https://loopback.io/doc/en/lb4/Creating-components.html#providers).
Providers support [dependency injection](https://loopback.io/doc/en/lb4/Binding.html#a-provider)
Expand Down Expand Up @@ -214,7 +214,7 @@ A proxy service acts as a proxy to an external service. A class service creates
an instance of a helper class. A provider service resolves a value.
All of them have access to the app, request, and response objects via dependency
injections, and can influence the handling of the request-response cycle.
injections, and can influence the handling of the request/response cycle.
Services can be injected in the controller constructor so controller methods may
use them.
Expand All @@ -237,7 +237,7 @@ may use them.
invocation of method on classes decorate with the `@intercept()` decorator.
All controllers, services, and repositories; and their methods can be intercepted.
This makes interceptors a powerful participant in the request-response cycle,
This makes interceptors a powerful participant in the request/response cycle,
since they can modify the request and response objects and call their methods.
{% include tip.html content="The [authorization component](https://loopback.io/doc/en/lb4/apidocs.authorization.html)
Expand All @@ -258,14 +258,17 @@ The app is configured to use the `MySequence` sequence.
Now this is a step-wise sequence of what happens when a request is made to
`http://localhost:4000/ping`.

1. The request is intercepted by `MySequence`.
2. The route is then identified by `FindRoute`. There is a handler for this request.
1. The request is dispatched to `MySequence` by the HTTP server.
2. The route is then identified by `FindRoute` based on the verb and path
defined by OpenAPI decorators. There is a handler for this request.
3. `ParseParams` then tries to parses any parameters might have been submitted.
There is none.
4. `InvokeMethod` then invokes the handler with empty parameters. It returns
whatever the handler returns, in this case, it is JSON object with `greeting`,
`date`, `url`, and `headers` properties.
There is none in this case.
4. `InvokeMethod` then invokes the handler with the resolved parameters, which is
empty in this case. It returns whatever the handler returns, in this case, it is
a JSON object with `greeting`, `date`, `url`, and `headers` properties.
5. `Send` then sends this JSON object back to the client.
6. `Reject` is in place to catch any errors that might be thrown in any
of the steps above.

#### Request to a non-controller endpoint

Expand Down

0 comments on commit d08a704

Please sign in to comment.