Page Contents

Preparing your API for consumption

Interacting with your API

We’ll use the repo loopback4-example-todo to demonstrate how Swagger UI can be used to test your endpoints.

First, git clone the repository, install its dependencies, and run the application:

lb4 example todo
cd loopback4-example-todo
npm start

Open http://localhost:3000/explorer to see the API endpoints defined by swagger.json.

10000000.png

The Swagger UI displays all of the endpoints defined in your application.

10000001.png

Clicking on one of the endpoints will show the endpoint’s documentation as defined in your API spec. Next, click on Try It Out to send a request to the endpoint. If the endpoint takes parameters, assign the values before the request is sent. If the parameter involves a body, a template is given for you to edit as specified in your spec. Click Execute to send the request:

10000002.png

The response to the request can be seen below the Execute button, where the response code and the body are displayed. Ideally, each endpoint should be tested with good and bad inputs to confirm that the returned responses are as expected.

Closing thoughts

Congratulations! You now have successfully created and tested an API with LoopBack 4. We hope you enjoy the test-drive. Your feedback matters and please share your thoughts with us.

This is just the beginning of the full LoopBack 4 developer experience. The first beta release lays out the new foundation of LoopBack for extension developers. It also demonstrates a path to create REST APIs from OpenAPI specs together with Controllers and Repositories. More features will be added in the coming weeks and months.

Here is a sneak peek of what’s coming:

The train is moving and welcome on board! Your participation and contribution will make LoopBack 4 an even more powerful framework and greater community/ecosystem. The team is very excited about the new journey. We look forward to working with you on more ideas, more pull requests, and more extension modules. Let’s make LoopBack 4 rock together!