-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: document the request-response cycle #4914
Conversation
91bbe7a
to
d6c9466
Compare
cad2d74
to
a2ced75
Compare
@hacksparrow It's a great start. I would like to see more information, such as:
|
This diagram can be useful too - https://loopback.io/pages/en/lb4/imgs/loopback-overview.png |
A few other things:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice writeup. I like the walk through part. And the diagram helps to understand the cycle. Just have a question about the non-controller endpoint part.
docs/site/Req-res-cycle.md
Outdated
Requests to non-controller endpoints are also intercepted by the app's sequence, | ||
but the control is handed over to the underlying Express middleware from the | ||
`InvokeMethod` phase, and never make it to `Send` unless the middleware calls | ||
`next()`. Unhandled error from Express middleware still reach `Reject`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how we show the differences between these two endpoints. But I am a bit confused about services
and the interceptor
part. From my understanding, the structure we show above is:
/ ==> controller endpoint -> Services, Interceptors -> repositories
Sequence ---
\ ==> non-controller endpoint
But IIUC I think the interceptors can also be use with non-controller endpoints. Maybe we make it more clear here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you point out where this structure is contradicted?
/ ==> controller endpoint -> Services, Interceptors -> repositories
Sequence ---
\ ==> non-controller endpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the interceptors cannot be used in non-controller endpoints. Is it true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interceptors work only on Controllers and Repositories, so non-controller endpoint handlers can't be intercepted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works on Services too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, global interceptors also intercept non-controller routes.
3218a8b
to
4d24da2
Compare
@hacksparrow , would this PR |
docs/site/Req-res-cycle.md
Outdated
### The request-response cycle | ||
|
||
The request-response cycle involves many components, especially if the request | ||
is to a controller-endpoint which interacts with a model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the request is to a controller-endpoint
-> the request is coming from a controller-endpoint
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it "interacts with the database".
@dhmlau only LB4 req-res. |
935ace2
to
df3c79d
Compare
@raymondfeng I have updated the PR with your inputs. However, since this PR is only for the flow of the request and the response, I have only mentioned your points from a high-level perspective. Your points should be covered in another doc, maybe titled "Writing extensions for the request-response cycle". |
docs/site/Req-res-cycle.md
Outdated
@@ -0,0 +1,278 @@ | |||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: let's name the file as Request-response-cycle.md
.
docs/site/Req-res-cycle.md
Outdated
title: 'Request-response cycle' | ||
keywords: LoopBack 4.0, LoopBack 4 | ||
sidebar: lb4_sidebar | ||
permalink: /doc/en/lb4/Application.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong html link. It should be /doc/en/lb4/Request-response-cycle.html
.
docs/site/Req-res-cycle.md
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request-responses
-> request/response
docs/site/Req-res-cycle.md
Outdated
permalink: /doc/en/lb4/Application.html | ||
--- | ||
|
||
## The LoopBack 4 request-response cycle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe request/response
?
docs/site/Req-res-cycle.md
Outdated
|
||
#### The sequence | ||
|
||
The sequence is a simple class with five injected helper methods. These five |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with five injected helper methods
-> with five injected helper methods by default
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it five injected helper methods in the constructor.
docs/site/Req-res-cycle.md
Outdated
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is intercepted by
-> 'is dispatched to MySequence by the http server`?
docs/site/Req-res-cycle.md
Outdated
`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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on the verb and path defined by OpenAPI decorators?
docs/site/Req-res-cycle.md
Outdated
2. The route is then identified by `FindRoute`. 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty parameters
-> resolved parameters which is empty in this case
?
docs/site/Req-res-cycle.md
Outdated
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. | ||
5. `Send` then sends this JSON object back to the client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's mention error handling here for Reject
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added: 6.
Reject is in place to catch any errors that might be thrown in any of the steps above.
d08a704
to
fcd5a17
Compare
@raymondfeng applied all your feedback. PTAL. |
@hacksparrow Please fix the formatting error with |
Document the LB4 request-response cycle. Signed-off-by: Yaapa Hage <[email protected]>
e571166
to
ab37b3f
Compare
Merging the PR per @hacksparrow's request. |
Document the LB4 request-response cycle.
Closes #4836
Signed-off-by: Yaapa Hage [email protected]
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈