https://github.com/ulisesgascon/simple-api
A very simple HTTP API to build fast prototypes
https://github.com/ulisesgascon/simple-api
Last synced: about 1 year ago
JSON representation
A very simple HTTP API to build fast prototypes
- Host: GitHub
- URL: https://github.com/ulisesgascon/simple-api
- Owner: UlisesGascon
- License: mit
- Created: 2023-03-19T14:21:33.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-20T14:44:35.000Z (over 1 year ago)
- Last Synced: 2025-03-30T13:53:26.114Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@ulisesgascon/simple-api
- Size: 2.05 MB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
@ulisesgascon/simple-api
A very simple HTTP API to build fast prototypes
# 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/todo` List all TODOS
- `POST /v1/todo` 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:
```bash
npx @ulisesgascon/simple-api
```
You can specify the port:
```bash
npx @ulisesgascon/simple-api 3000
```
## Module ๐ฆ
Using `@ulisesgascon/simple-api` in your project:
```js
const appInitialization = require('@UlisesGascon/simple-api')
;(async () => {
const app = await appInitialization()
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](https://expressjs.com/en/4x/api.html#app)
**PRO TIP** By default Swagger validator will be disabled as adding new routes can be complicated, but you can enable it:
```js
const appInitialization = require('@UlisesGascon/simple-api')
;(async () => {
const app = await appInitialization({
swaggerEnabled: true
})
app.listen(3000, () => console.log(`Server listening on port 3000!`))
})()
```
## Docker Version ๐ณ
Use Docker Hub:
```bash
# 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:
```bash
# 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
```bash
git clone https://github.com/UlisesGascon/simple-api.git
cd simple-api
```
## Install
```bash
nvm use
npm i
```
## Start
```bash
# Regular
npm run start
# prettier logs:
npm run dev
```
## Test
```bash
npm run test:coverage
```
## Linting
```bash
npm run lint
npm run lint:fix
```
## Formatting
```bash
npm run format
npm run format:fix
```
## Contributing
Please consult [CONTRIBUTING](https://github.com/UlisesGascon/.github/blob/main/contributing.md) for guidelines on contributing to this project.
## Author
**@ulisesgascon/simple-api** ยฉ [Ulises Gascรณn](https://github.com/ulisesgascon), Released under the [MIT](./LICENSE) License.