Resource Config

This page explains how to configure your resources (storage and apis)

Global config object

The bedoon configuration object must have a “db” attribute with the url of your mongo database and a resources attribute which contains all your resources config like this :

var config = {
    db: "mongodb://localhost/mydatabase",
    resources: {
        resource_name: {
            // resource config details
        }
    }
};

Resource config object

A resource have a type (“document” is the default type), and an schema that contains resource attributes, relations ... A basic resource configuration look like this :

resource_name: {
    type: 'document'
    schema: {
        attributes: {
            attribute1: String,
            attribute2: String
        }
    }
}

The above resource will create a mongo document called “resource_name” and each record will have two attributes, “attribute1” and “attribute2” and an auto-generated “_id” attribute. This will also create the following apis :

Find All

GET /resource_name # To retrieve all the records

response:

{
    status: "success",
    data: [
        {
            _id: "id",
            attribute1: "value",
            attribute2: "value"
        }

        // ...
    ]
}

Find One

GET /resource_name/:id # To retrieve a record by its id

response:

{
    status: "success",
    data: {
        _id: "id",
        attribute1: "value",
        attribute2: "value"
    }
}

Find Query

GET /resource_name?attribute1=value # To retrieve records with some filters

response:

{
    status: "success",
    data: [
        {
            _id: "id",
            attribute1: "value",
            attribute2: "value"
        }

        // ...
    ]
}

Create a record

POST /resource_name # To retrieve a record by its id

request body:

{
    attribute1: "value",
    attribute2: "value"
}

response:

{
    status: "success",
    data: {
        _id: "id",
        attribute1: "value",
        attribute2: "value"
    }
}

Update a record

PUT /resource_name/:id # To retrieve a record by its id

request body:

{
    _id: "id",
    attribute1: "value",
    attribute2: "value"
}

response:

{
    status: "success",
    data: {
        _id: "id",
        attribute1: "value",
        attribute2: "value"
    }
}

Delete a record

DELETE /resource_name/:id # To retrieve a record by its id