Restapify
Restapify is a tool that allows you to easily and quickly deploy a local REST API using an intuitive and developer friendly JSON file structure.
Summary
Why Restapify
Features
- 💻 Incredible DX - Intuitive files structure and JSON syntax
- ✅ JSON valid - You will only use
.json
files that follows the ECMA-404 standard - 🎛 Dashboard - Out of the box SPA to get an overview of your API and manage the routes states
- 🔥 Built in hot watcher - Directly see your changes after a file update
- 📝 Fakerjs implementation - Intuive syntax to use to easily populate your API responses
- 🚨 Events handler - Execute callbacks on specific events
- 🏷️ TypeScript support
Getting Started
Using the cli
The simplest way to use Restapify is to use his cli:
npm i -g restapify-cli
and then serve the api folder:
restapify serve path/to/folder/
Read more about the cli here.
Using the JavaScript class
You can install restapify's class using npm
(note that this package should be a devDependency):
npm i -D restapify
You can then import the class and instanciate it to serve the api folder:
import Restapify from 'restapify'
const apiFolderPath = path.resolve(__dirname, './path/to/folder')
const rpfy = new Restapify({
rootDir: apiFolderPath
})
rpfy.run()
Contributing
All remarks are welcome so feel free to open an issue.
Wants to collaborate? Please read the contributing guidelines.
Documentation
File structure
Restapify allow you to easily create REST API routes using a specific file structure. Take the following folder api/
for example:
📂 api
┣ 📂 users
┃ ┗ 📜 *.json
┃ ┗ 📜 [userid].json
┃ ┗ 📜 [userid].DELETE.204.json
┣ 📂 posts
┃ ┗ 📜 [postid].json
┃ ┗ 📜 my-post.PUT.json
┣ 📜 posts.json
It will serve the following routes:
GET /users
GET /users/:userid
DELETE /users/:userid
GET /posts
GET /posts/:postid
PUT /posts/my-post
File name
{scope}.{method}.{statusCode}.{state}.json
scope
:
Fixed value
The following file structure...
📂 api
┣ 📂 posts
┃ ┗ 📜 my-post.json
┣ 📜 posts.json
...will serve the following routes:
GET /posts
GET /posts/my-post
Star selector
The following file structure...
📂 api
┣ 📂 posts
┃ ┗ 📜 *.json
┣ 📜 *.json
...will serve the following routes:
GET /
GET /posts
Variable
File content
The content of the json
file will correspond to the body of the response. For example if the file /api/users/*.json
contains this content:
[
{
"id": 1,
"name": "bob"
},
{
"id": 2,
"name": "alice"
}
]
...you will get it as the request's body:
let response = await fetch('/api/users')
let body = await response.json()
console.log(body)