Documentation

Learn how to create databases and use the REST API.

Visit the blog for in-depth articles and tutorials.

Join our FB group to interact with the restdb.io team and active users.


Database REST API

One of the core features of the restdb.io database cloud service is the Restful API which automatically reflects your database schema. All restdb.io databases have a unique URL as a REST endpoint. Client applications communicate through the URL with JSON objects.

Collection REST API

A database collection (same as a SQL table) contains your JSON documents. All JSON documents gets a unique _id.

Http VerbResourceFunctionality
GEThttps://<dburl>.restdb.io/rest/<collection>Get list of JSON documents from database collection
GEThttps://<dburl>.restdb.io/rest/<collection>/IDGet one document from a collection. ID must be a valid ObjectID
GEThttps://<dburl>.restdb.io/rest/<collection>/ID/<subcollection>Get list of documents from subcollection (subcollection is field name of type child)
GEThttps://<dburl>.restdb.io/rest/<collection>/ID/<subcollection>/IDGet document from subcollection (subcollection is field name of type child) and ID is a valid ObjectID
POSThttps://<dburl>.restdb.io/rest/<collection>Create a new document in a collection. Request body is a valid JSON document.
POSThttps://<dburl>.restdb.io/rest/<collection>/ID/<subcollection>Create a child document in a sub collection.
POST arrayhttps://<dburl>.restdb.io/rest/<collection>Post array data. Request body is an array of JSON documents. Optional parameter validate=false, for bulk inserts without validation. Will also work for child documents
PUThttps://<dburl>.restdb.io/rest/<collection>/IDUpdate a document in a collection. Request body is a valid JSON document.
PATCHhttps://<dburl>.restdb.io/rest/<collection>/IDUpdate one or more properties on a document in a collection. Request body is a valid JSON object.
DELETEhttps://<dburl>.restdb.io/rest/<collection>/IDDelete a document in a collection
DELETE arrayhttps://<dburl>.restdb.io/rest/<collection>/*Delete an array of documents in a collection. Request body must be an array of ID's
DELETE queryhttps://<dburl>.restdb.io/rest/<collection>/*?q={...}Delete a list of documents in a collection. List is based on query in parameter ?q={...}. Only allowed with a full access api-key.

HTTPS is required. The restdb.io database REST API only responds to encrypted traffic so that your data remains safe. All API traffic must have a valid apikey or authorization JWT token as a parameter or as a request header field.

Read more about how to query database here.

Media Content API

Http VerbResourceFunctionality
GEThttps://<dburl>.restdb.io/media/IDGet binary data for media object with ID. ID is a valid ObjectID for an object in the media archive or an existing filename. Parameter s options; ?s=t (thumbnail), ?s=w (web) and ?s=o (original size). No API-key required.
GEThttps://<dburl>.restdb.io/media/ID/metaGet JSON structure with media object metadata. Requires API-key.
POSThttps://<dburl>.restdb.io/mediaPost file(s) using the multipart/formdata protocol, view example. Requires API-key.
PUThttps://<dburl>.restdb.io/mediaNot yet implemented
DELETEhttps://<dburl>.restdb.io/media/IDDelete media content with ID. Requires API-key

Read more about media archive here

Meta Data API

Http VerbResourceFunctionality
GEThttps://<dburl>.restdb.io/rest/_metaGet meta data for the database as a JSON object
GEThttps://<dburl>.restdb.io/rest/<collection>/_metaGet meta data for the collection as a JSON object

Mail API

Http VerbResourceFunctionality
POSThttps://<dburl>.restdb.io/mailSend email. Request body contains one document:
{"to": "...", "subject": "...", "html": "...", "company": "...", "sendername": "..."}
, or an array of documents […]

Quick example

For our test database, the REST endpoint URL is:

https://rdb-simpledb.restdb.io/rest

GET - read all items from a collection with rest api

    curl -i -H "Accept: application/json"\
     -H "Content-Type: application/json"\
     -H "x-apikey: 560bd47058e7ab1b2648f4e7"\
     -X GET "https://rdb-simpledb.restdb.io/rest/product"

Run in Postman

Example database output from GET Restful request above:

    [
        {
            "_id": "5602647c7f98025500000041",
            "description": "Saepe adipisci illo restful dignissimos. Dicta generate occaecati ex ducimus.",
            "name": "Quaerat consectetur",
            "photos": [
                "55a68f6fc53a0b2a00000006"
            ],
            "serialno": "16177"
        },
        {
            "_id": "5602647c7f9802550000003c",
            "description": "Harum voluptas vitae restful consequatur with rest api.",
            "name": "Ratione iste recusandae",
            "photos": [
                "55a68f6fc53a0bbc00000009"
            ],
            "serialno": "23588"
        }
    ]

GET - read one database item from a collection requires an unique objectID (the _id field)

    curl -i -H "Accept: application/json"\
     -H "Content-Type: application/json"\
     -H "x-apikey: 560bd47058e7ab1b2648f4e7"\
     -X GET 'https://rdb-simpledb.restdb.io/rest/product/5602647c7f98025500000041'

Run in Postman

See complete code examples below for most popular programming languages.

Code examples in popular languages

GET all documents from the motorbikes collection
curl -k -i -H "Content-Type: application/json"\
-H "x-apikey: 560bd47058e7ab1b2648f4e7"\
-X GET 'https://inventory-fac4.restdb.io/rest/motorbikes'
GET one record by ID
curl -k -i -H "Content-Type: application/json"\
-H "x-apikey: 560bd47058e7ab1b2648f4e7"\
-X GET 'https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7'
GET records by query
curl -k -i -H "Content-Type: application/json"\
-H "x-apikey: 560bd47058e7ab1b2648f4e7"\
-G 'https://inventory-fac4.restdb.io/rest/motorbikes' -d 'q={"field":"value"}'
POST a new record to collection
curl -k -H "Content-Type: application/json"\
-H "x-apikey: 560bd47058e7ab1b2648f4e7"\
-X POST -d '{"field1":"xyz","field2":"xyz"}' 'https://inventory-fac4.restdb.io/rest/motorbikes'
PUT an updated record to collection by ID
curl -k -H "Content-Type: application/json"\
-H "x-apikey: 560bd47058e7ab1b2648f4e7"\
-X PUT -d '{"field2":"xyz"}' 'https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7'
DELETE a record by ID
curl -k -H "Content-Type: application/json"\
-H "x-apikey: 560bd47058e7ab1b2648f4e7"\
-X DELETE 'https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7'
JavaScript using jQuery AJAX

GET all documents from the motorbikes collection
var settings = {
    "async": true,
    "crossDomain": true,
    "url": "https://inventory-fac4.restdb.io/rest/motorbikes",
    "method": "GET",
    "headers": {
      "content-type": "application/json",
      "x-apikey": "560bd47058e7ab1b2648f4e7",
      "cache-control": "no-cache"
    }
}
                  
$.ajax(settings).done(function (response) {
    console.log(response);
});
                    
POST a new document to the motorbikes collection
var jsondata = {"field1": "xyz","field2": "abc"};
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://inventory-fac4.restdb.io/rest/motorbikes",
  "method": "POST",
  "headers": {
    "content-type": "application/json",
    "x-apikey": "560bd47058e7ab1b2648f4e7",
    "cache-control": "no-cache"
  },
  "processData": false,
  "data": JSON.stringify(jsondata)
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
                    
PUT a updated document to the motorbikes collection
var jsondata = {"field1": "new value","field2": "xxx"};
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7",
  "method": "PUT",
  "headers": {
    "content-type": "application/json",
    "x-apikey": "560bd47058e7ab1b2648f4e7",
    "cache-control": "no-cache"
  },
  "processData": false,
  "data": JSON.stringify(jsondata)
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
                    
DELETE a document from the motorbikes collection
var settings = {
    "async": true,
    "crossDomain": true,
    "url": "https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7",
    "method": "DELETE",
    "headers": {
    "content-type": "application/json",
    "x-apikey": "560bd47058e7ab1b2648f4e7",
    "cache-control": "no-cache"
    }
}

$.ajax(settings).done(function (response) {
    console.log(response);
});
JavaScript using XHR AJAX

GET all documents from the motorbikes collection
var data = null;

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
    if (this.readyState === 4) {
    console.log(this.responseText);
    }
});

xhr.open("GET", "https://inventory-fac4.restdb.io/rest/motorbikes");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("x-apikey", "560bd47058e7ab1b2648f4e7");
xhr.setRequestHeader("cache-control", "no-cache");

xhr.send(data);
                    
POST a new document to the motorbikes collection
var data = JSON.stringify({
    "field1": "xyz",
    "field2": "xyz"
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
    if (this.readyState === 4) {
    console.log(this.responseText);
    }
});

xhr.open("POST", "https://inventory-fac4.restdb.io/rest/motorbikes");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("x-apikey", "560bd47058e7ab1b2648f4e7");
xhr.setRequestHeader("cache-control", "no-cache");

xhr.send(data);
                    
PUT a updated document to the motorbikes collection
var data = JSON.stringify({
    "field2": "new value"
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
    if (this.readyState === 4) {
    console.log(this.responseText);
    }
});

xhr.open("PUT", "https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("x-apikey", "560bd47058e7ab1b2648f4e7");
xhr.setRequestHeader("cache-control", "no-cache");

xhr.send(data);
                    
DELETE a document from the motorbikes collection
var data = null;
                    
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
    if (this.readyState === 4) {
    console.log(this.responseText);
    }
});

xhr.open("DELETE", "https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("x-apikey", "560bd47058e7ab1b2648f4e7");
xhr.setRequestHeader("cache-control", "no-cache");

xhr.send(data);
                    
NodeJS using the request library
GET all documents from the motorbikes collection
var request = require("request");

var options = {
    method: 'GET',
    url: 'https://inventory-fac4.restdb.io/appdeploy/motorbikes',
    headers: 
    {   'cache-control': 'no-cache',
        'x-apikey': '560bd47058e7ab1b2648f4e7' 
    } 
};

request(options, function (error, response, body) {
    if (error) throw new Error(error);
    console.log(body);
});
                    
POST a new document to the motorbikes collection
var request = require("request");

var options = { 
    method: 'POST',
    url: 'https://inventory-fac4.restdb.io/rest/motorbikes',
    headers: 
    {   'cache-control': 'no-cache',
        'x-apikey': '560bd47058e7ab1b2648f4e7',
        'content-type': 'application/json' },
    body: { field1: 'xyz', field2: 'abc' },
    json: true 
};

request(options, function (error, response, body) {
    if (error) throw new Error(error);
    console.log(body);
});

                    
PUT an updated document to the motorbikes collection
var request = require("request");

var options = { 
    method: 'PUT',
    url: 'https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7',
    headers: 
    {   'cache-control': 'no-cache',
        'x-apikey': '560bd47058e7ab1b2648f4e7',
        'content-type': 'application/json' },
    body: { field2: 'new value' },
    json: true 
};

request(options, function (error, response, body) {
    if (error) throw new Error(error);
    console.log(body);
});

                    
DELETE a document from the motorbikes collection
var request = require("request");

var options = { 
    method: 'DELETE',
    url: 'https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7',
    headers: 
    {   'cache-control': 'no-cache',
        'x-apikey': '560bd47058e7ab1b2648f4e7',
        'content-type': 'application/json' 
    }
};

request(options, function (error, response, body) {
    if (error) throw new Error(error);
    console.log(body);
});
Java using Unirest
GET all documents from the motorbikes collection
HttpResponse response = Unirest.get("https://inventory-fac4.restdb.io/appdeploy/motorbikes")
.header("x-apikey", "560bd47058e7ab1b2648f4e7")
.header("cache-control", "no-cache")
.asString();
                    
POST a new document to the motorbikes collection
HttpResponse response = Unirest.post("https://inventory-fac4.restdb.io/rest/motorbikes")
.header("content-type", "application/json")
.header("x-apikey", "560bd47058e7ab1b2648f4e7")
.header("cache-control", "no-cache")
.body("{\"field1\":\"xyz\",\"field2\":\"abc\"}")
.asString();
                    
PUT an updated document to the motorbikes collection
HttpResponse response = Unirest.put("https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7")
.header("content-type", "application/json")
.header("x-apikey", "560bd47058e7ab1b2648f4e7")
.header("cache-control", "no-cache")
.body("{\"field2\":\"new value\"}")
.asString();
                    
DELETE a document from the motorbikes collection
HttpResponse response = Unirest.delete("https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7")
.header("content-type", "application/json")
.header("x-apikey", "560bd47058e7ab1b2648f4e7")
.header("cache-control", "no-cache")
.asString();
Pythod using request
GET all documents from the motorbikes collection
import requests

url = "https://inventory-fac4.restdb.io/rest/motorbikes"

headers = {
    'content-type': "application/json",
    'x-apikey': "560bd47058e7ab1b2648f4e7",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)
                    
POST a new document to the motorbikes collection
import requests
import json

url = "https://inventory-fac4.restdb.io/rest/motorbikes"

payload = json.dumps( {"field1": "xyz","field2": "abc"} )
headers = {
    'content-type': "application/json",
    'x-apikey': "560bd47058e7ab1b2648f4e7",
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
                    
PUT an updated document to the motorbikes collection
import requests

url = "https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7"

payload = "{\"field2\":\"new value\"}"
headers = {
    'content-type': "application/json",
    'x-apikey': "560bd47058e7ab1b2648f4e7",
    'cache-control': "no-cache"
    }

response = requests.request("PUT", url, data=payload, headers=headers)

print(response.text)
                    
DELETE a document from the motorbikes collection
import requests

url = "https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7"

headers = {
    'content-type': "application/json",
    'x-apikey': "560bd47058e7ab1b2648f4e7",
    'cache-control': "no-cache"
    }

response = requests.request("DELETE", url, headers=headers)

print(response.text)
                    
PHP using HttpRequest
GET all documents from the motorbikes collection
setUrl('https://inventory-fac4.restdb.io/rest/motorbikes');
$request->setMethod(HTTP_METH_GET);

$request->setHeaders(array(
'cache-control' => 'no-cache',
'x-apikey' => '560bd47058e7ab1b2648f4e7',
'content-type' => 'application/json'
));

try {
    $response = $request->send();
    echo $response->getBody();
} catch (HttpException $ex) {
    echo $ex;
}
                    
POST a new document to the motorbikes collection
setUrl('https://inventory-fac4.restdb.io/rest/motorbikes');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
'cache-control' => 'no-cache',
'x-apikey' => '560bd47058e7ab1b2648f4e7',
'content-type' => 'application/json'
));

$request->setBody('{"field1":"xyz","field2":"abc"}');

try {
    $response = $request->send();
    echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
                    
PUT an updated document to the motorbikes collection
setUrl('https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7');
$request->setMethod(HTTP_METH_PUT);

$request->setHeaders(array(
'cache-control' => 'no-cache',
'x-apikey' => '560bd47058e7ab1b2648f4e7',
'content-type' => 'application/json'
));

$request->setBody('{"field2":"new value"}');

try {
    $response = $request->send();
    echo $response->getBody();
} catch (HttpException $ex) {
    echo $ex;
}
                    
DELETE a document from the motorbikes collection
setUrl('https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7');
$request->setMethod(HTTP_METH_DELETE);

$request->setHeaders(array(
'cache-control' => 'no-cache',
'x-apikey' => '560bd47058e7ab1b2648f4e7',
'content-type' => 'application/json'
));

try {
    $response = $request->send();
    echo $response->getBody();
} catch (HttpException $ex) {
    echo $ex;
}
                    
C# using Resharpr
GET all documents from the motorbikes collection
var client = new RestClient("https://inventory-fac4.restdb.io/rest/motorbikes");
var request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("x-apikey", "560bd47058e7ab1b2648f4e7");
request.AddHeader("content-type", "application/json");
IRestResponse response = client.Execute(request);
                    
POST a new document to the motorbikes collection
var client = new RestClient("https://inventory-fac4.restdb.io/rest/motorbikes");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("x-apikey", "560bd47058e7ab1b2648f4e7");
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\"field1\":\"xyz\",\"field2\":\"abc\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
                    
PUT an updated document to the motorbikes collection
var client = new RestClient("https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7");
var request = new RestRequest(Method.PUT);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("x-apikey", "560bd47058e7ab1b2648f4e7");
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\"field2\":\"new value\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
                    
DELETE a document from the motorbikes collection
var client = new RestClient("https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7");
var request = new RestRequest(Method.DELETE);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("x-apikey", "560bd47058e7ab1b2648f4e7");
request.AddHeader("content-type", "application/json");
IRestResponse response = client.Execute(request);
                    
Objective-C using NSURL
GET all documents from the motorbikes collection
#import 

NSDictionary *headers = @{ @"content-type": @"application/json",
                        @"x-apikey": @"560bd47058e7ab1b2648f4e7",
                        @"cache-control": @"no-cache";

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://inventory-fac4.restdb.io/rest/motorbikes"]
                                                    cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                    timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:headers];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask =   [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];
                    
POST a new document to the motorbikes collection
#import 

NSDictionary *headers = @{ @"content-type": @"application/json",
                        @"x-apikey": @"560bd47058e7ab1b2648f4e7",
                        @"cache-control": @"no-cache" };
NSDictionary *parameters = @{ @"field1": @"xyz",
                            @"field2": @"abc" };

NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://inventory-fac4.restdb.io/rest/motorbikes"]
                                                    cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                    timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask =   [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];
                    
PUT an updated document to the motorbikes collection
#import 

NSDictionary *headers = @{ @"content-type": @"application/json",
                        @"x-apikey": @"560bd47058e7ab1b2648f4e7",
                        @"cache-control": @"no-cache" };
NSDictionary *parameters = @{ @"field2": @"new value" };

NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https:///inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7"]
                                                    cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                    timeoutInterval:10.0];
[request setHTTPMethod:@"PUT"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask =   [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];
                    
DELETE a document from the motorbikes collection
#import 

NSDictionary *headers = @{ @"content-type": @"application/json",
                        @"x-apikey": @"560bd47058e7ab1b2648f4e7",
                        @"cache-control": @"no-cache" };

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7"]
                                                    cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                    timeoutInterval:10.0];
[request setHTTPMethod:@"DELETE"];
[request setAllHTTPHeaderFields:headers];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask =   [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];
                    
Swift using NSURL
GET all documents from the motorbikes collection
import Foundation

let headers = [
"content-type": "application/json",
"x-apikey": "560bd47058e7ab1b2648f4e7",
"cache-control": "no-cache"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://inventory-fac4.restdb.io/rest/motorbikes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                        timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
    if (error != nil) {
        print(error)
    } else {
        let httpResponse = response as? HTTPURLResponse
        print(httpResponse)
    }
})

dataTask.resume()
                    
POST a new document to the motorbikes collection
import Foundation

let headers = [
"content-type": "application/json",
"x-apikey": "560bd47058e7ab1b2648f4e7",
"cache-control": "no-cache"
]
let parameters = [
"field1": "xyz",
"field2": "abc"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://inventory-fac4.restdb.io/rest/motorbikes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                        timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
    if (error != nil) {
        print(error)
    } else {
        let httpResponse = response as? HTTPURLResponse
        print(httpResponse)
    }
})

dataTask.resume()
                    
PUT an updated document to the motorbikes collection
import Foundation

let headers = [
"content-type": "application/json",
"x-apikey": "560bd47058e7ab1b2648f4e7",
"cache-control": "no-cache"
]
let parameters = ["field2": "new value"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https:///inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                        timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
    if (error != nil) {
        print(error)
    } else {
        let httpResponse = response as? HTTPURLResponse
        print(httpResponse)
    }
})

dataTask.resume()
                    
DELETE a document from the motorbikes collection
import Foundation

let headers = [
"content-type": "application/json",
"x-apikey": "560bd47058e7ab1b2648f4e7",
"cache-control": "no-cache"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://inventory-fac4.restdb.io/rest/motorbikes/560bd66201e7ab1b2648f4e7")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                        timeoutInterval: 10.0)
request.httpMethod = "DELETE"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
    if (error != nil) {
        print(error)
    } else {
        let httpResponse = response as? HTTPURLResponse
        print(httpResponse)
    }
})

dataTask.resume()