How to Use API Connect to Manage LoopBack APIs
Learn how to use Loopback with API Connect to track API use.
Join the DZone community and get the full member experience.Join For Free
as an example i used a simple sample application ‘approval requests’ built on the clean stack. the sample is available as open source and comes with several apis. in this blog article i focus on two of these apis:
1. login users, and
2. get a list of users which requires user authentication.
the api connect service basically adds a layer on top of the loopback api implementation. rather than calling the loopback apis directly the apis of the api connect service are invoked. this allows the service to track usage of the apis. developers can use developer portals, register their applications and subscribe to api plans.
in the sample below i created the api definitions manually via the api connect dashboard and used a proxy to forward the requests to the actual api implementations. in other words, what i describe here works the same way for other types of api implementations and not just for loopback.
first i defined the two paths and their input parameters. in the case of ‘login’ json is required which includes an user name and a password. the output is an access_token which is passed to all other api invocations to identify the authenticated user.
the next screenshot shows how to enforce client ids. api consumers get their own client ids when registering applications in the developer portal. with the api connect service you can also use additionally a client secret.
in the next step i defined the assembly. in my case i simply use a proxy to my loopback application. the important parts are the two variables to make sure that the access_tokens are always forwarded and to map the paths defined in the api connect service to the paths of the underlying api implementations.
in the developer portal api consumers can subscribe to api plans and invoke the two apis.
api owners can see analytics of their apis in the api connect dashboard, for example how many apis were invoked at which time by which application.
Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.