Code Monkey home page Code Monkey logo

simple-api's Introduction

@ulisesgascon/simple-api

A very simple HTTP API to build fast prototypes

npm version license downloads Known Vulnerabilities

About

A very simple HTTP API to build fast prototypes

❤️ Awesome Features:

  • Typical Sample API with all the expected things (cors, fast response, immutability, etc..) 🚩
  • Basic JSON storage without external dependencies or third party solutions 🔥
  • Great testing coverage 🧪
  • Easy to customize ⚙️
  • Great Documentation with Swagger 📚
  • Available as Npx, module, docker image and more... with a single command 📦

Available Routes

Important:

  • By running npm run sample:generate you will regenerate a new TODOs dataset
  • The server allows CRUD Operations but this operations are not affecting the dataset at all

Endpoints:

  • GET /__/health check health
  • GET /__/docs Swagger documentation for all the available endpoints
  • GET /v1/todos List all TODOS
  • POST /v1/todos Create a TODO
  • GET /v1/todo/{id} Get a specific TODO
  • PUT /v1/todo/{id} Update a specific TODO
  • PATCH /v1/todo/{id} PAtch a specific TODO property
  • DELETE /v1/todo/{id} Delete a specific TODO

PRO TIP Run simple-api and check the Swagger docs with payload details and great UI 🍿

Usage

Command line 🪄

Using Node.js's npx to start a simple api in local:

npx @ulisesgascon/simple-api

You can specify the port:

npx @ulisesgascon/simple-api 3000

Module 📦

Using @ulisesgascon/simple-api in your project:

const app = require('@UlisesGascon/simple-api')()

app.listen(3000, () => console.log(`Server listening on port 3000!`))

You can use app to extend the routes as it is the Typical express application

PRO TIP By default Swagger validator will be disabled as adding new routes can be complicated, but you can enable it:

const app = require('@UlisesGascon/simple-api')({
  swaggerEnabled: true
})

app.listen(3000, () => console.log(`Server listening on port 3000!`))

Docker Version 🐳

Use Docker Hub:

# Pull the image from Docker Hub:
docker pull ulisesgascon/simple-api:latest

# Run container:
docker run -p 3000:3000 ulisesgascon/simple-api:latest

To build and run the container locally:

# Clone Repo:
git clone https://github.com/ulisesgascon/simple-api.git

# Change to repo's cloned directory:
cd simple-api

# Build Image locally:
docker build --no-cache -t ulisesgascon/simple-api:latest .

# Run container:
docker run -p 3000:3000  ulisesgascon/simple-api:latest

Development 🚀

Clone

git clone https://github.com/UlisesGascon/simple-api.git
cd simple-api

Install

nvm use
npm i

Start

# Regular
npm run start

# prettier logs:
npm run dev

Test

npm run test:coverage

Linting

npm run lint
npm run lint:fix

Formatting

npm run format
npm run format:fix

Contributing

Please consult CONTRIBUTING for guidelines on contributing to this project.

Author

@ulisesgascon/simple-api © Ulises Gascón, Released under the MIT License.

simple-api's People

Contributors

ulisesgascon 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.