-
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
feat(docs): migration guide for remoting hooks #4426
Conversation
eac3ef2
to
afa2744
Compare
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 start with a detailed content 👍 . Some comment on vague parts.
@agnes512 thank you for thoughtful comments. I have slightly reworked the overall structure of this page and renamed few section titles. Is the high-level picture more clear now? @hacksparrow thank you for the review too, do you have any more comments? I pushed a new commit 6b27dad that improves the older text and adds the remaining pieces. I consider this page as done and ready for final review(s). @strongloop/loopback-maintainers PTAL. |
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.
👍 Very detailed and well organized contents!
Reviewed the sections before " Modifying request parameters", LGTM so far. Will take a look of the rest and try the get current user tomorrow.
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 quickly scan through and it looks good to me. I like the structure especially the part that how users can modify their LB3 artifacts to corresponding LB4 methods/classes. Just some nitpicks!
|
||
In order to reject a request and return an error HTTP response, just throw an | ||
error from your interceptor. As explained in | ||
[Handling errors in controllers](../../Controllers.html#handling-errors-in-controllers), |
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 don't know if Controllers.html
should be Controllers.md
?
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.
Good catch! I was copying full URLs from https://loopback.io and changing them to local paths. I have to review all links and replace .html
to .md
where appropriate.
Thank you for catching this problem! ❤️
are registered for models. | ||
|
||
In LoopBack 4, the REST API is implemented by controllers that are decoupled | ||
from models, therefore interceptor are registered and invoked on controller |
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.
interceptor
-> interceptors
// ... | ||
} | ||
} | ||
``` | ||
|
||
## Accessing context data | ||
|
||
(to be done) | ||
In LoopBack 3, a remoting hooks receives a context object providing both |
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.
This sentence is a bit long.
Suggestion:
In LoopBack 3, a remoting hook receives a context object providing both transport-specific data, such as the HTTP request & response objects, and transport-independent data, such as the array of input arguments for the remote method and the result of remote method invocation.
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 am going to rework this paragraph into a list.
In LoopBack 3, a remoting hook receives a context object providing:
- Transport-specific data like the HTTP request & response objects.
- Transport-independent data, for example the array of input arguments for the
remote method and the result of remote method invocation.
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.
LGTM 👏
|
||
{% include note.html content=" In LoopBack 3, a model class has three | ||
responsibilities: a model describing shape of data, a repository providing | ||
data-access APIs, and a controller implementing REST API). Both remoting hooks |
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: closing bracket but no opening one
|
||
In LoopBack 4, the REST API is implemented by controllers that are decoupled | ||
from models, therefore interceptor are registered and invoked on controller | ||
classes/method, not on a model classes/methods. " %} |
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.
method
-> methods
method is invoked. | ||
|
||
{% include warning.html content=" | ||
If your interceptor is registered for more than a single method, then extra care is needed to ensure your interceptor is making valid assumption about the arguments expected by the target controller method. |
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: assumption
-> assumptions
|
||
## Accessing the current user | ||
|
||
LoopBack 4 does not provide authentication layer out of the box, it relies on |
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: ,
-> ;
about the current user. | ||
|
||
If you are using the official | ||
[LoopBack Authentication Extension](../../lb4/Loopback-component-authentication.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.
../../lb4/Loopback-component-authentication.html
-> ../../Loopback-component-authentication.md
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 have very limited knowledge about remoting hooks in LB3, but your PR is clear to me. LGTM.
I have one suggestion to consider, please see my review comment. Thanks!
) { | ||
try { | ||
// Add pre-invocation logic here | ||
const result = await next(); |
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.
Just a suggestion.. Referencing the next paragraph, would it be helpful to mention as a comment here something like:
// add code from beforeRemote hook here
If that's the case, we can also flip the order of the 2 paragraphs 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.
This code snippet is showing the the interceptor implementation as created by lb4 interceptor
, I'd like to keep it as-is.
I like the idea of making it more explicit where to put before/after remote hooks, I'll update the code snippet in the example below.
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.
👏 LGTM
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.
Great write-up, Miroslav!
49f5e8c
to
36fbdae
Compare
Signed-off-by: Miroslav Bajtoš <[email protected]>
b68386e
to
0da51b1
Compare
Resolve #3950:
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 👈