0.0.20 • Published 10 years ago

apibox v0.0.20

Weekly downloads
22
License
MIT
Repository
github
Last release
10 years ago

apibox

Create declarative APIs in few minutes

0. Requirements

  • Node.js
  • NPM
  • MongoDB

1. Install

mkdir myapi
cd myapi
npm install --save apibox

2. Configure

Save the following file as config.js

module.exports = {
    "db": "test", // the name of the MongoDB database
    "collection": "data", // the name of the MongoDB Collection
    "documentation": "./docs.yml", // the file where the API is declared
    "api": {
        "hostname": "localhost",
        "port": 9987
    },
    "cors": {
        "activate": false, // activate Cross-origin resource sharing
        "hostname": "example.com"   
    }
};

and then document your API entrypoints in your docs.yml (or somewhere else, if you defined another location in your config.js)

resourcePath: /api/v1
description: Test API Entrypoint
apis:

- path: /
  operations:

  - httpMethod: GET
    summary: Get all entries
    notes: All entries will be sent back to the client
    responseClass: Entries
    nickname: getAllEntries
    consumes: 
        - application/json

- path: /entry/
  operations:

  - httpMethod: GET
    summary: Get a single entry
    notes: Return only one entry object
    responseClass: Entry
    nickname: getEntry
    consumes: 
        - application/json
    parameters:

      - name: name
        description: The name you are searching for
        paramType: query
        dataType: string
        required: true

  - httpMethod: POST
    summary: Post a new entry
    notes: Return the object "message ok" if worked
    nickname: PostEntry
    consumes: 
        - application/json
    parameters:

      - name: name
        description: The name of the new entry
        paramType: query
        dataType: string

models:
  Entry:
    id: _id
    properties:
      name:
        type: String

Please refer to the Swagger-core API Declaration specification editing your docs.yml

3. Run!

If you didn't it before, add the folder ./node_modules/.bin to your PATH, so you will be able to access the commands provided by the installed node.js modules.

export PATH="$PATH:./node_modules/.bin"

and finally run the server using

apibox-serve

Open your browser at http://localhost:9987/docs (or the domain/port you have choosen) to see it working.

If you want to use the CLI, you can run for example:

apibox-cli
0.0.20

10 years ago

0.0.19

10 years ago

0.0.18

10 years ago

0.0.17

10 years ago

0.0.16

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago