• Stars
    star
    108
  • Rank 321,259 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

$ api-now - Launch an API Server to serve a JSON, JS file, GraphQL or faker data with HTTPS support.

πŸ• api-now

Launch an API Server to serve a JSON, JS file, GraphQL or faker data with HTTPS support.

Based on json-server with more features:

  • Default datasets out-of-the-box: todos, users, posts, comments (using faker). Just run $ api-now
  • HTTPS support (with key, cert files).
  • Can take a .json or .js file.
  • GraphQL endpoint to serve faker data: /graphql
  • Can serve a static directory (e.g. /dist, /public etc.)
  • APIs support pagination (_page, _limit).
  • /echo route to respond parameters back as json.
  • /file route to serve any file type (including images).
  • /login route (POST) to respond with a dummy JWT token (using jsonwebtoken).
  • /todos route to return a list of todo items (follow TodoMVC specs).
  • /image/random to serve a random image file from a directory.
  • /avatar/random to serve a random avatar image.
  • /nature/random to serve a random nature image.

πŸ”§ Install

  • As a dependency: $ npm install api-now
  • As a global command: $ npm install api-now -g
  • Or run it without installing: $ npx api-now

πŸ“– Usage

$ api-now

That's it! You can try it now:

$ curl http://localhost:3003/todos
$ curl http://localhost:3003/users?_page=1&_limit=5    (others: /posts /comments)

Other Useful Routes:
$ curl http://localhost:3003/echo?any=value
$ curl http://localhost:3003/file?path=YourFilePath
$ curl http://localhost:3003/image/random?path=YourDirPath
$ curl http://localhost:3003/avatar/random
$ curl http://localhost:3003/nature/random
$ curl -X POST http://localhost:3003/login -H 'Content-Type: application/json' -d '{"username": "test"}'

Open GraphQL Query Page:
open http://localhost:3003/graphql

$ curl 'http://localhost:3003/graphql' -H 'Content-Type: application/json' --data-binary '{"query":"{ todos { title } }"}'

πŸ“– Serve data from a file

Create db.json file, then run api-now to start a HTTPS server at port 3003:

{
  "posts": [
    { "id": 1, "title": "Post title 1" },
    { "id": 2, "title": "Post title 2" }
  ]
}
$ api-now db.json
$ api-now -k keyFile -c certFile -p 3003 -w db.json

Or create a .js file and use "faker" data like generateData.js

πŸ“– Command line options:

Usage: api-now [options] [json or js file]
Options:
  -c, --cert <certFile>  HTTPS cert file
  -k, --key <keyFile>    HTTPS key file
  -p, --port <port>      Use custom port
  -s, --static <dir>     Serve static directory (examples: ./dist, ./public)
  -v, --version          Show version
  -w, --watch            Watch for changes and reload (default: false)
  -h, --help             Output usage information

πŸ“– Tips

  • json-server - Repo & Documents

  • Command line to generate self-signed Key & Cert files:

openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj "/C=US/ST=California/L=San Francisco/O=Organization/CN=CommonName" -keyout key.pem -out cert.pem

Development

All contributions are welcome!

More Repositories

1

react-tabulator

React Tabulator is based on tabulator - a JS table library with many advanced features.
CSS
357
star
2

node-rem

Node REM - NodeJS Rest Express MongoDB and more: typescript, passport, JWT, socket.io, HTTPS, HTTP2, async/await, nodemailer, templates, pagination, docker, etc. Live Demo: https://node-rem-ngduc.vercel.app
TypeScript
237
star
3

react-setup

A Universal React Setup with i18n: Babel 6, Koa 2, React, React Router, React Transmit, React Bootstrap, React-intl, Mocha, Isparta, Webpack 2, Storybook, InlineCSS/PostCSS, ESLint, HTTPS & HTTP2.
JavaScript
175
star
4

life-calendar

Life Calendar: Your Life in Weeks
TypeScript
155
star
5

vercel-express

Vercel Express and UI Webapp Example. Live Demo - https://vercel-express-ngduc.vercel.app/
TypeScript
67
star
6

Thin-PHP-Framework

A micro web framework - lightweight and flexible open source PHP5 MVC framework
PHP
41
star
7

parcelui

Parcel + Typescript + React/Preact + Router + CSS Modules + SASS + Jest + Api-Now + Github Actions CI
TypeScript
35
star
8

ui-form-field

ui-form-field based on formik - a simple way to work with Forms in React.
CSS
21
star
9

json-now

$ json-now - Launch an API Server to serve data from a JSON, JS file or faker data with HTTPS support. Based on json-server.
JavaScript
18
star
10

dashb

Dashb.io - Minimalist's Dashboard and Widgets.
HTML
12
star
11

flatten-sol

command-line tool to flatten a solidity contract which uses `import "@openzeppelin/contracts/...`.
JavaScript
11
star
12

mstime

a lightweight module (2KB gzip) to measure & visualize code performance in millisecond (ms), run on Node & browser. No dependencies!
JavaScript
11
star
13

portable-react

Simple React components written in Typescript using Tailwind CSS, all in one index.tsx file ~ 200 lines of code.
TypeScript
8
star
14

ez-react-form

A simple way to work with Forms in React.
CSS
8
star
15

rails-react-typescript-jest

Rails + React + Typescript + Jest UI app
Ruby
7
star
16

syntax-wiki

Source code for "syntax.wiki" website
HTML
7
star
17

create-blank-app

create-blank-app (cba) - just one command to remember - create a blank app.
JavaScript
6
star
18

dev-benchmark

Benchmark script to measure performance of usual development tools.
Shell
4
star
19

mystik

Mystik (MkTable) is a generic Javascript DAO (Data Access Objects) for database systems including NoSQL databases, Redis, NodeJS support and REST API web service handling.
JavaScript
3
star
20

react-18-ts-vite-app

React 18, Typescript, Vite and Vercel.
TypeScript
3
star
21

react-tabulator-examples

Created with CodeSandbox
JavaScript
3
star
22

framework-demos

FrameworkDemos.com is a place to show online web framework demos, online mobile framework demos, or library, UI control demos
JavaScript
2
star
23

better-pull-request

Better comment styles for Github Pull Request.
2
star
24

awesome-stellar

awesome resources about Stellar ecosystem
2
star
25

vercel-flask-ui

Vercel + Flask + UI
HTML
2
star
26

ez-formik

Easy-to-use components to use with formik - hence the name ez-formik.
CSS
2
star
27

crunchk.com

crunchk.com website
TypeScript
1
star
28

eth-fund

A site that lists campaigns or missions for fundraising, accepts any crypto tokens easily with transparency and NFT badges.
TypeScript
1
star
29

create-react-form

create-react-form - CRF
JavaScript
1
star
30

clean-up-action

Github Action to clean up resources.
JavaScript
1
star
31

px-elements

Polymer Elements, Web Components
HTML
1
star
32

px-test-utils

helper functions for mocha unit tests using teaspoon, react-addons-test-utils, etc.
JavaScript
1
star
33

forevercloud

Publish article, content using blockchain technology.
JavaScript
1
star
34

es5-html-elements

react-native-html-elements is a fork from @expo/html-elements but using "import * as" syntax.
TypeScript
1
star
35

px-login

React minimal reusable Login Component.
TypeScript
1
star
36

docker

Dockerfiles for lightweight dev/production images.
Dockerfile
1
star