Git Product home page Git Product logo

api-moka's Introduction

api-moka

๐Ÿ‘ท๐Ÿปโ€โ™‚๏ธ Generate a mock service / emulator from OpenAPI specs!

This tool creates a simple Express/NodeJS server from a given OpenAPI spec file or url. Once created you can run a client against the emulated API and make live changes to the emulated service.

It's useful to mock out dependencies for speeding up development, especially in a microservice environment where there are a lot of service dependencies.

Prerequisites

  • VS Code
  • OpenApi VS Code extension that can preview OpenAPI with the Swagger Editor
  • Node 18
  • TypeScript installed globally

Generate the emulator

Build the tool and install (public npm package will be coming):

npm i
npm run build
npm i -g

Run it:

api-moka -o "mocks" -s "test/communicationservicesrooms.json" "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/communication/data-plane/Identity/stable/2023-08-01/CommunicationIdentity.json" --run

This command

  • generates a simple Express server for your APIs
  • opens the new project in VS Code
  • builds the server and starts it
  • hot-reload is supported!
  • to only generate the code, don't pass the --run argument

The structure of the generated server is as follows:

src/
  {service}/
    api.ts
    openapi.json
  app.ts

Try it!

While the generated emulator is running:

  • Open an openapi.json from one of the services and launch the preview to see it in Swagger Editor
  • Open the corresponding api.ts side-by-side
  • In Swagger Editor, choose a route and click "Try It"
  • Fill in all required request properties and headers
  • Click "Execute"
  • You can see the returned response from the emulator!
  • To change the returned response, edit the route in api.ts and save the file
  • Wait until hot-reload did its thing and execute the request again, you will see your changes in the response.

VS Code screenshot

api-moka's People

Contributors

dominikme avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.