Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@gasbuddy/configured-swagger-client

Package Overview
Dependencies
Maintainers
3
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gasbuddy/configured-swagger-client

A module that creates a set of swagger clients with support for inter-service tracing, custom certificates, and separated endpoint configuration

latest
npmnpm
Version
5.7.0
Version published
Maintainers
3
Created
Source

configured-swagger-client

wercker status

GasBuddy has chosen Swagger as our API format for all services. Luckily, a growing number of partners are also using Swagger. Our services are written mostly in Node.js, and this module is an attempt to make the process of wiring a Node.js project to Swagger services easier and more robust.

We have a variety of "independent components":

  • -api - a Swagger API that is reachable by the outside world
  • -serv - a Swagger API that is only reachable from other services
  • -web - a non-Swagger service that exposts
  • -job - a start-and-finish job that runs periodically or on demand

All of these components likely make use of other Swagger services. Each of these services is defined by a JSON swagger specification and will use small-swagger-codegen to generate a client package. This is a departure from versions < 5.x of this library which generated a JSON spec and the client was dynamically generated. THe value of pregeneration is full type information available at development time, which includes autocompleting complex method names and request structures, which in a language like Javascript, can reduce bugs significantly without losing the flexibility (since it's just a generator doing the typing work).

One of the other important things we do is create a "CorrelationId" - a single identifier which can be traced all through the logs of all of the services that request touches. This module creates an easy way to pass that CorrelationId along in dependent service calls.

See the tests for example usage, but here's a simple one:

import PetApi from 'a-node-module-from-small-swagger-codegen';

const petApi = new PetApi(req.gb.serviceFactory);

const pets = await services.Pets.findPetsByStatus({ status: 'pending' });
// pets.obj has your pets!

API Options

The CorrelationId support is accomplished via a requestInterceptor option to the rest-api-support methods. rest-api-support also supports adding headers (such as authorization headers) in this phase. Metric collection is also enabled by the requestInterceptor/responseInterceptor pair.

Keywords

gasbuddy

FAQs

Package last updated on 11 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts