All Projects → anttiviljami → Openapi Client Axios

anttiviljami / Openapi Client Axios

Licence: mit
JavaScript client library for consuming OpenAPI-enabled APIs with axios

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Openapi Client Axios

Swagger Axios Codegen
swagger client to use axios and typescript
Stars: ✭ 143 (-14.88%)
Mutual labels:  swagger, openapi, axios
Swagger Ui
Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
Stars: ✭ 21,279 (+12566.07%)
Mutual labels:  swagger, openapi, hacktoberfest
Pode
Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
Stars: ✭ 329 (+95.83%)
Mutual labels:  swagger, openapi, hacktoberfest
Redoc
📘 OpenAPI/Swagger-generated API Reference Documentation
Stars: ✭ 15,935 (+9385.12%)
Mutual labels:  swagger, openapi, hacktoberfest
Express Jsdoc Swagger
Swagger OpenAPI 3.x generator
Stars: ✭ 69 (-58.93%)
Mutual labels:  swagger, openapi, hacktoberfest
Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+1952.38%)
Mutual labels:  swagger, openapi, hacktoberfest
Goa
Design-based APIs and microservices in Go
Stars: ✭ 4,493 (+2574.4%)
Mutual labels:  swagger, hacktoberfest, openapi
Openapi Backend
Build, Validate, Route, Authenticate and Mock using OpenAPI
Stars: ✭ 216 (+28.57%)
Mutual labels:  swagger, openapi, hacktoberfest
Openapi Spring Webflux Validator
🌱 A friendly kotlin library to validate API endpoints using an OpenApi 3.0 and Swagger 2.0 specification
Stars: ✭ 67 (-60.12%)
Mutual labels:  swagger, openapi, hacktoberfest
Apispec
A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification)..
Stars: ✭ 831 (+394.64%)
Mutual labels:  swagger, openapi, hacktoberfest
Openapi Cli
⚒️ OpenAPI 3 CLI toolbox with rich validation and bundling features.
Stars: ✭ 169 (+0.6%)
Mutual labels:  swagger, openapi, hacktoberfest
Netcoreblockly
.NET Core API to Blockly - generate from WebAPI, Swagger, OData, GraphQL =>
Stars: ✭ 121 (-27.98%)
Mutual labels:  swagger, openapi, hacktoberfest
Loopback Next
LoopBack makes it easy to build modern API applications that require complex integrations.
Stars: ✭ 3,972 (+2264.29%)
Mutual labels:  swagger, openapi, hacktoberfest
Schemathesis
A modern API testing tool for web applications built with Open API and GraphQL specifications.
Stars: ✭ 768 (+357.14%)
Mutual labels:  swagger, openapi, hacktoberfest
Swagger Combine
Combines multiple Swagger schemas into one dereferenced schema.
Stars: ✭ 102 (-39.29%)
Mutual labels:  swagger, openapi, hacktoberfest
Mentorship Backend
Mentorship System is an application that matches women in tech to mentor each other, on career development, through 1:1 relations during a certain period of time. This is the backend of this system.
Stars: ✭ 132 (-21.43%)
Mutual labels:  swagger, openapi, hacktoberfest
Prance
Resolving Swagger/OpenAPI 2.0 and 3.0 Parser
Stars: ✭ 133 (-20.83%)
Mutual labels:  swagger, openapi
Terraform Provider Openapi
OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)
Stars: ✭ 134 (-20.24%)
Mutual labels:  swagger, openapi
Swaggerassertions
Assert your API requests and responses match with your swagger definition
Stars: ✭ 137 (-18.45%)
Mutual labels:  swagger, openapi
Rapipdf
PDF generation from OpenAPI / Swagger Spec
Stars: ✭ 132 (-21.43%)
Mutual labels:  swagger, openapi

openapi-client-axios

CI Dependencies npm version npm downloads bundle size Total alerts Language grade: JavaScript License Sponsored Buy me a coffee

JavaScript client library for consuming OpenAPI-enabled APIs with axios. Types included.

Features

  • [x] Create API clients from OpenAPI v3 definitions
  • [x] Easy to use API to call API operations using JavaScript methods
    • client.getPet(1)
    • client.searchPets()
    • client.searchPets({ ids: [1, 2, 3] })
    • client.updatePet(1, payload)
  • [x] Built on top of the robust axios JavaScript library
  • [x] Isomorphic, works both in browser and Node.js
  • [x] Generate TypeScript definitions (.d.ts) for your APIs with full IntelliSense support

Documentation

See DOCS.md

Quick Start

npm install --save axios openapi-client-axios
yarn add axios openapi-client-axios

With promises / CommonJS syntax:

const OpenAPIClientAxios = require('openapi-client-axios').default;

const api = new OpenAPIClientAxios({ definition: 'https://example.com/api/openapi.json' });
api.init()
  .then(client => client.getPetById(1))
  .then(res => console.log('Here is pet id:1 from the api', res.data));

With async-await / ES6 syntax:

import OpenAPIClientAxios from 'openapi-client-axios';

const api = new OpenAPIClientAxios({ definition: 'https://example.com/api/openapi.json' });
api.init();

async function createPet() {
  const client = await api.getClient();
  const res = await client.createPet(null, { name: 'Garfield' });
  console.log('Pet created', res.data);
}

Client

OpenAPI Client Axios uses operationIds in OpenAPIv3 definitions to call API operations.

After initalizing OpenAPIClientAxios, an axios client instance extended with OpenAPI capabilities is exposed.

Example:

const api = new OpenAPIClientAxios({ definition: 'https://example.com/api/openapi.json' });
api.init().then((client) => {
  client.updatePet(1, { age: 12 });
});

client is an axios instance initalized with baseURL from OpenAPI definitions and extended with extra operation methods for calling API operations.

It also has a reference to OpenAPIClientAxios at client.api

Operation methods

OpenAPIClientAxios operation methods take 3 arguments:

client.operationId(parameters?, data?, config?)

Parameters

The first argument is used to pass parameters available for the operation.

// GET /pets/{petId}
client.getPet({ petId: 1 })

For syntactic sugar purposes, you can also specify a single implicit parameter value, in which case OpenAPIClientAxios will look for the first required parameter for the operation. Usually this is will be a path parameter.

// GET /pets/{petId} - getPet
client.getPet(1)

Alternatively, you can explicitly specify parameters in array form. This method allows you to set custom parameters not defined in the OpenAPI spec.

// GET /pets?search=Garfield - searchPets
client.searchPets([{ name: 'search', value: 'Garfield', in: 'query' }])

The type of the parameters can be any of:

  • query
  • header
  • path
  • cookie

Data

The second argument is used to pass the requestPayload

// PUT /pets/1 - updatePet
client.updatePet(1, { name: 'Odie' })

More complex payloads, such as Node.js streams or FormData supported by Axios can be used.

The first argument can be set to null if there are no parameters required for the operation.

// POST /pets - createPet
client.updatePet(null, { name: 'Garfield' })

Config object

The last argument is the config object.

The config object is an AxiosRequestConfig object. You can use it to override axios request config parameters, such as headers, timeout, withCredentials and many more.

// POST /user - createUser
client.createUser(null, { user: 'admin', pass: '123' }, { headers: { 'x-api-key': 'secret' } });

Paths Dictionary

OpenAPI Client Axios also allows calling API operations via their path and HTTP method, using the paths dictionary.

Example:

client.paths['/pets'].get(); // GET /pets, same as calling client.getPets()
client.paths['/pets'].post(); // POST /pets
client.paths['/pets/{petId}'].put(1); // PUT /pets/1
client.paths['/pets/{petId}/owner/{ownerId}'].get({ petId: 1, ownerId: 2 }) ; // GET /pets/1/owner/2

This allows calling operation methods without using their operationIds, which may be sometimes preferred.

Generating type files (.d.ts)

TypeScript IntelliSense

openapi-client-axios comes with a tool called typegen to generate typescript type files (.d.ts) for OpenAPIClient instances using an OpenAPI definition file.

$ npm install -g openapi-client-axios-typegen
Usage: typegen [file]

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

Examples:
  typegen ./openapi.yml > client.d.ts  - generate a type definition file

The output of typegen exports a type called Client, which can be used for instances created with OpenAPIClientAxios.

Both the api.getClient() and api.init() methods support passing in a Client type.

import { Client as PetStoreClient } from './client.d.ts';

const client = await api.init<PetStoreClient>();
const client = await api.getClient<PetStoreClient>();

typegen supports using both local and remote URLs for OpenAPI definition files.

$ typegen ./petstore.yaml
$ typegen https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml

Contributing

OpenAPI Client Axios is Free and Open Source Software. Issues and pull requests are more than welcome!

The Chilicorn

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].