Robolt is a frontend helper class for projects using Robogo and Axios. The aim is to provide an easy to use and flexible way to communicate with robogo.
We take no responsibility for any demage done by this package.
If you find anything that isn't working or not up to the documentation, please open issue or a pull request over on github.
Thank You in advance!
A very simple example:
import Robolt from 'robolt'
import axios from 'axios'
// configure axios here if needed (eg.: baseURL) before creating the robolt instance
const robolt = new Robolt(axios, 'api')
// robolt is ready to be used!
The constructor uses the following parameters:
Parameter | Type | Description | Default |
---|---|---|---|
axios | Function | The axios function preconfigured | |
prefix | String | The prefix that was used when the routes of robogo were registered to express.js | |
serveStaticPath | String | The path where the files are static hosted. Same as in the constructor of robogo | 'static' |
defaultFilter | Object | A MongoDB filter object. Every request's filter will be this object if no filter was provided | {} |
This section will describe the methods of robolt that are available to use. These are organized in seven categories: Create, Read, Update, Delete, Service, File and Special.
Every create method returns a Promise that is resolved with the result or rejected with an error.
Sends a POST request to the '/create/:model' route of robogo with the given data.
- Method: POST
- Resolves: Object (MongoDB document)
this.$API.Create(modelName, documentObject)
.then( document => ... )
.catch( error => ... )
key | type | description |
---|---|---|
modelName | String | Name of the model registered in robogo |
documentObject | Object | Object matching the schema of the model |
Every read method returns a Promise that is resolved with the result or rejected with an error.
Sends a GET request to the '/read/:model' route of robogo with the given data.
- Method: GET
- Resolves: Array<Object (MongoDB document)>
this.$API.Read(modelName[, optionsObject ])
.then( documents => ... )
.catch( error => ... )
key | type | description | example |
---|---|---|---|
filter | Object | Mongodb query | {friends: 'Chandler'} |
projection | Array<String> | Fields to include in results. Uses MongoDB projection. | ['username', 'friends'] |
sort | Object | Mongodb sort | { age : 1 } |
skip | Number | The number of documents to skip in the results set. | 10 |
limit | Number | The number of documents to include in the results set. | 5 |
Sends a GET request to the '/get/:model/:id' route of robogo with the given data.
- Method: GET
- Resolves: Object (MongoDB document)
this.$API.Get(modelName, documentId[, optionsObject ])
.then( document => ... )
.catch( error => ... )
key | type | description | example |
---|---|---|---|
projection | Array<String> | Fields to include in projection. | ['username', 'friends'] |
Sends a GET request to the '/search/:model' route of robogo with the given data.
- Method: GET
- Resolves: Array<Object (MongoDB document)>
this.$API.Search(modelName[, optionsObject ])
.then( documents => ... )
.catch( error => ... )
key | type | description | example |
---|---|---|---|
filter | Object | Mongodb query | {friends: 'Chandler'} |
projection | Array<String> | Fields to include in results. Uses MongoDB projection. | ['username', 'friends'] |
threshold | Number | Fuse.js threshold, defaults to 0.4 | 0.6 |
keys | Array<String> | Keys of the document that are searched in. If no keys are provided all keys of the document will be used. | ['username'] |
depth | Number | If no keys are provided, we can limit the depth of the keys to be picked from the schema, starts from 0, defaults to Infinity | 2 |
term | String | Search term that is searched for | 'search term' |
Every update method returns a Promise that is resolved with the result or rejected with an error.
Sends a PATCH request to the '/update/:model' route of robogo with the given data.
- Method: PATCH
- Resolves: WriteResults
this.$API.Update(modelName, documentObject)
.then( result => ... )
.catch( error => ... )
An object with an _id field containing the ObjectId of the document we want to update and the fields we want to change with their new values.
Every delete method returns a Promise that is resolved with the result or rejected with an error.
Sends a DELETE request to the '/delete/:model/:id' route of robogo with the given document _id.
- Method: DELETE
- Resolves: WriteResults
this.$API.Delete(modelName, documentId)
.then( result => ... )
.catch( error => ... )
Every service method returns a Promise that is resolved with the result or rejected with an error.
Sends a POST request to the '/runner/:service/:function' route of robogo with the given data.
- Method: POST
- Resolves: Any
this.$API.RunService(serviceName, functionName, params)
.then( result => ... )
.catch( error => ... )
key | type | description |
---|---|---|
serviceName | String | Name of the service (.js file) registered in robogo |
functionName | String | Name of the function inside the service |
params | Any | The parameters that the service awaits |
Sends a GET request to the '/getter/:service/:function' route of robogo with the given data.
- Method: GET
- Resolves: Any
this.$API.GetService(serviceName, functionName, params)
.then( result => ... )
.catch( error => ... )
key | type | description |
---|---|---|
serviceName | String | Name of the service (.js file) registered in robogo |
functionName | String | Name of the function inside the service |
params | Any | The parameters that the service awaits |
Sends a POST (multipart/form-data) request to the '/fileupload' route of robogo with the given file.
- Method: POST
- Returns: Promise<RoboFile document>
this.$API.UploadFile(file[, percentCallback])
.then( result => ... )
.catch( error => ... )
key | type | description |
---|---|---|
file | File | File instance, eg.: from a file input |
percentCallback | Function | Callback that will be called multiple times, while the file is uploading. Its parameter is a number between 0 and 100 |
Returns the file's absolute and relative URLs where it is static hosted by robogo. If a thumbnail was also created it also returns the thumbnail's URLs.
- Returns: {absolutePath, relativePath[, absoluteThumbnailPath, relativeThumbnailPath]}
this.$API.GetFileURLs(file)
RoboFile document to the file
Downloads the file for a RoboFile document from robogo.
- Method: GET
- Returns: Promise<File>
this.$API.GetFile(file[, percentCallback])
key | type | description |
---|---|---|
file | String/Object | Either the whole RoboFile document of the file or its _id |
percentCallback | Function | Callback that will be called multiple times, while the file is downloading. Its parameter is a number between 0 and 100 |
Downloads the file for a RoboFile document from robogo and returns a local URL for it.
- Method: GET
- Returns: Promise<String>
this.$API.GetFileURL(file[, percentCallback])
key | type | description |
---|---|---|
file | String/Object | Either the whole RoboFile document of the file or its _id value |
percentCallback | Function | Callback that will be called multiple times, while the file is downloading. Its parameter is a number between 0 and 100 |
Downloads the thumbnail file for a RoboFile document from robogo.
- Method: GET
- Returns: Promise<File>
this.$API.GetThumbnail(file[, percentCallback])
key | type | description |
---|---|---|
file | String/Object | Either the whole RoboFile document of the file or its _id value |
percentCallback | Function | Callback that will be called multiple times, while the file is downloading. Its parameter is a number between 0 and 100 |
Downloads the thumbnail file for a RoboFile document from robogo and returns a local URL for it.
- Method: GET
- Returns: Promise<String>
this.$API.GetThumbnailURL(file[, percentCallback])
key | type | description |
---|---|---|
file | String/Object | Either the whole RoboFile document of the file or its _id value |
percentCallback | Function | Callback that will be called multiple times, while the file is downloading. Its parameter is a number between 0 and 100 |
Sends a DELETE request to the '/filedelete/:id' route of robogo with the given file id.
- Method: DELETE
- Returns: Promise<Empty>
this.$API.DeleteFile(file)
.then( result => ... )
.catch( error => ... )
Either the whole RoboFile document of the file or its _id.
Every special method returns a Promise that is resolved with the result or rejected with an error.
Sends a GET request to the '/model' or the 'model/:model' route of robogo, depending on wether the modelName parameter was given.
- Method: GET
- Resolves into: Array<Object>|Object
this.$API.Model(modelName)
.then( model => ... )
.catch( error => ... )
Sends a GET request to the '/schema/:model' route of robogo.
- Method: GET
- Resolves into: Object
this.$API.Schema(modelName)
.then( schema => ... )
.catch( error => ... )
Sends a GET request to the '/fields/:model' route of robogo.
- Methods: GET
- Resolves into: Array of Objects
this.$API.Fields(modelName, depth)
.then( fields => ... )
.catch( error => ... )
Number that limits the depth of the fields to be returned. Starts from 0, defaults to Infinity.
Returns the same result as the Schema method, but reintroduces circular references, that were stripped out by Robogo before sending the data to the frontend.
- Method: GET
- Resolves into: Object
this.$API.RecycledSchema(modelName)
.then( schema => ... )
.catch( error => ... )
Sends a GET request to the '/count/:model' route of robogo.
- Methods: GET
- Resolves into: Number
this.$API.Count(modelName[, filter])
.then( count => ... )
.catch( error => ... )
MongoDB filter object
Sends a GET request to the '/searchkeys/:model' route of robogo.
- Methods: GET
- Resolves into: Array<String>
this.$API.SearchKeys(modelName[, depth])
.then( keys => ... )
.catch( error => ... )
Number, that limits the depth of the keys to be picked from the model's schema
Every contribution is more then welcomed. If you have an idea or made some changes to the code, please open an issue or a pull request at the package's github page.
- Horváth Bálint
- Zákány Balázs