Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restapify

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restapify

<img src="https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg?style

  • 0.0.26
  • npm
  • Socket score

Version published
Weekly downloads
927
decreased by-27.75%
Maintainers
1
Weekly downloads
 
Created
Source

Restapify

codecov Gitmoji

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) // [{"id":1,"name":"bob"},{"id":2,"name":"alice"}]

FAQs

Package last updated on 09 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc