Skip to content
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: create REST API endpoints in components + LB3 migration #5385

Merged
merged 1 commit into from
May 14, 2020

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented May 11, 2020

This is a part of documentation for the spike #4099 How to migrate LB3 components.

In this pull request, I am covering migration of REST API endpoints.

  • Create a new page for component authors to explain how to contribute REST API endpoints
  • Create a new page for component authors to explain how to contribute local service classes or providers
  • Create a migration guide explaining how to migrate REST API endpoints from LoopBack 3 components to LoopBack 4 style.
    This is a part of a spike, so I should not be changing the real docs, but then I figured out that since I have already wrote the content, it will give more value to our users to put the content up, even if it's not finished yet. My intention is to land this pull request even if the content is not in the shape we would eventually want and create follow-up stories to make any substantial improvements as required by reviewers. (This the the part where I am getting back to our usual spike process - do the research and then open follow-up stories to implement the proposed changes.)

@raymondfeng @jannyHou @emonddr: please review

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

REST API explorer has a flag `useSelfHostedSpec` that controls whether a new
endpoint serving OpenAPI document is added.

## Dynamic OpenAPI metadata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use https://loopback.io/doc/en/lb4/Booting-an-Application.html#boot-an-application-using-component for some of the use cases. I was able to modify the binding key and other metadata for services/controllers/... loaded by booters by override the app.service(), app.controller() for the subapp.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the pointer, I agree "booting an app using component" is a concept that can be useful when migrating LB3 extensions to LB4. However, I don't see how to apply it to "Dynamic OpenAPI metadata". I opened a new issue to document "booting an app using component" for extension authors in a holistic way - see #5422

Express router in your LoopBack 4 component and contribute it to the target
application.

2. Take the implementation of Express routes from your LoopBack 3 component and
Copy link
Contributor

@raymondfeng raymondfeng May 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Express routes can be added to a router using router.use(). The router can be plugged into LoopBack as an ExpressRequestHandler (express middleware handler function).

Copy link
Member Author

@bajtos bajtos May 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Express routes can be added to a router using router.use().

I am going to clarify this in https://github.com/strongloop/loopback-next/blob/docs/component-migration-rest-api/docs/site/extending/rest-api.md#express-routes

The router can be plugged into LoopBack as an ExpressRequestHandler (express middleware handler function).

I am not familiar with this new style. For now, I am recommending app.mountExpressRouter(), which has the benefit of allowing users to provide OpenAPI spec description of the Express routes too.

I opened #5423 to update the docs for extension authors and explain when & how to use this new concept.

Copy link
Contributor

@raymondfeng raymondfeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few minor comments. Great write-up.

Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice content! LGTM, a few nitpicks. 🚢

docs/site/extending/rest-api.md Outdated Show resolved Hide resolved
docs/site/extending/rest-api.md Outdated Show resolved Hide resolved
docs/site/extending/rest-api.md Outdated Show resolved Hide resolved
- Create a new page for component authors to explain how to contribute
  REST API endpoints

- Create a new page for component authors to explain how to contribute
  local service classes or providers

- Create a migration guide explaining how to migrate REST API endpoints
  from LoopBack 3 components to LoopBack 4 style.

Signed-off-by: Miroslav Bajtoš <[email protected]>
@bajtos bajtos force-pushed the docs/component-migration-rest-api branch from 4f2ec43 to 43affa4 Compare May 14, 2020 08:26
@bajtos bajtos merged commit 6277f60 into master May 14, 2020
@bajtos bajtos deleted the docs/component-migration-rest-api branch May 14, 2020 08:42
@bajtos
Copy link
Member Author

bajtos commented May 14, 2020

Thank you @raymondfeng and @jannyHou for the review and comments, I highly appreciate them 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants