0.0.6 • Published 6 years ago

protocrud v0.0.6

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
6 years ago

protocrud

A CLI that starts a server that makes any CRUD REST request work instantly.

Requirements

  • nodejs
  • mongodb

Installing

For global use run

npm install --global protocrud

For use in a project:

yarn add -D protocrud or npm install -D protocrud

Usage

Run protocrud in your shell, a server has now started where every restful endpoint will be available.

Example for a todo model:

Request MethodUrlDescriptionResponse
GET/todoFetches all todosAn array of todos
GET/todo/:idFetches a single todo by idA single todo
POST/todoCreates a todoThe newly created todo
PUT/todo/:idUpdates a todoThe updated todo
DELETE/todo/:idDeletes a todoVoid

The todo model (as seen in the url) is arbitrary, you can use any model name you like.

Configuration

To configure protocrud you can add a protocrud.config.json file next to your package.json, a custom path to the config file can be provided using the --config=path/to/config.json flag. You can override the config file by providing options to the cli, such as the --clean flag

protocrud.config.json
{
    "port": "1234",
    "clean": false,
    "db": {
        "name": "database-name"
    }
}

Initial Data

When using protocrud for a project, it can be useful to provide some initial data for your colleagues. This can be provided by creating a protocrud.data.json file like so:

protocrud.data.json
{
    "todo": [
        {
            "title": "Try protocrud",
            "completed": false
        },
        {
            "_id": "5b7deb5c18e71715587dfde7",
            "title": "Read protocrud documentation",
            "completed": true
        }
    ]
}

Options

You can provide several options to the protocrud cli to use a different database or port for example.

All of these can also be used in the protocrud.config.json file, options with dots in their names refer to deep objects, see protocrud.config.json

OptionDefaultUsageDescription
port1342protocrud --port=1342The port the protocrud server will be listening on.
cleanfalseprotocrud --cleanRemoves all data when starting, imports data from the configured data file if it exists.
config"protocrud.config.json"protocrud --config=protocrud.config.jsonPath to the protocrud.config.json file.
prefix""protocrud --prefix=/apiPath to listen on for requests, with a prefix of /api requests look like GET /api/todo
data"protocrud.data.json"protocrud --data=protocrud.data.jsonPath to the file with "clean" or initial data.
db.name"protocrud"protocrud --db.name=protocrudThe name of the mongo database that should be used to store data.
db.hostname"localhost"protocrud --db.hostname=localhostThe hostname the mongo db server is running on
db.port27017protocrud --db.port=27017The port the mongo db server is running on
db.userundefinedprotocrud --db.user=usernameThe user used to connect to the mongo db server
db.passwordundefinedprotocrud --db.password=usernameThe password used to connect to the mongo db server