Alexander Mills
Alexander Mills

Reputation: 99959

Loopback - get list of API endpoints via REST

Loopback has nice documentation which you can view at

http://<your-domain>:<your-port>/explorer

I want to write some tests for our server, and at the very least do a GET request for each of the endpoints that should be public and available over REST.

Loopback explorer clearly has this information somewhere - is there a way to get a list of endpoints programmatically?

I just want something like this list:

PATCH /ServicecontractViews 
GET /ServicecontractViews 
PUT /ServicecontractViews 
POST /ServicecontractViews 
PATCH /ServicecontractViews/{id} 
GET /ServicecontractViews/{id}
HEAD /ServicecontractViews/{id}
GET /Notes/{id} 
HEAD /Notes/{id}
PUT /Notes/{id}
DELETE /Notes/{id}
GET /Notes/{id}/exists 

is it possible to get this information programmatically (while the server is live)?

Upvotes: 0

Views: 2848

Answers (2)

Rodrigo
Rodrigo

Reputation: 454

A bit late, but I found this really useful, you can export to many formats, for example to generate a documentation in html you can do
openapi-generator-cli generate -g html -i http://localhost:3000/openapi.json -o ./html
and you get a nice page wich has a section Table of Contents with the exact list what you are asking for.
There are many generators, you can check all in https://openapi-generator.tech/docs/generators/
For example there are for documentation, to make a client like angular, or a server like python-flask.

Upvotes: 0

Matt Hamann
Matt Hamann

Reputation: 1638

The LoopBack explorer uses Swagger JSON to generate the UI you see.

If you watch the XHR requests using your browser debugger, you can grab the direct URL to the raw Swagger. This data should contain what you need, though not in quite as concise a format as you probably want.

Upvotes: 1

Related Questions