feat(docs): migration guide for remoting hooks#4426
Conversation
eac3ef2 to
afa2744
Compare
agnes512
left a comment
There was a problem hiding this comment.
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. |
jannyHou
left a comment
There was a problem hiding this comment.
👍 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.
agnes512
left a comment
There was a problem hiding this comment.
👏 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.
I don't know if Controllers.html should be Controllers.md?
There was a problem hiding this comment.
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.
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.
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.
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.|
|
||
| {% 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.
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. " %} |
| 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.
Nitpick: assumption -> assumptions
|
|
||
| ## Accessing the current user | ||
|
|
||
| LoopBack 4 does not provide authentication layer out of the box, it relies on |
| 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.
../../lb4/Loopback-component-authentication.html -> ../../Loopback-component-authentication.md
dhmlau
left a comment
There was a problem hiding this comment.
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.
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.
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.
emonddr
left a comment
There was a problem hiding this comment.
Great write-up, Miroslav!
49f5e8c to
36fbdae
Compare
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
b68386e to
0da51b1
Compare
Resolve #3950:
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated👉 Check out how to submit a PR 👈