Functions

For each model, functions can be created to create, read, update and deleted the model (CRUD). If the CRUD functions are not sufficient, custom business logic can be added.

CRUD


For each model, multiple READ, UPDATE, and DELETE functions can be created, but only one CREATE function.

Function
HTTP-Method
Description

CREATE

POST

Creates a new database entry of the model and returns it to the client.

READ

GET

Finds a single database entry of the model by a path and/or query parameters and returns it to the client.

READ_ALL

GET

Finds multiple database entries of the model and returns it to the client. Can be specified by query parameters.

UPDATE

PUT

Updates an existing database entry and returns it to the client. Can be specified by path and query parameters.

DELETE

DELETE

Deletes an existing database entry and returns it to the client. Can be specified by path and query parameters.

Path Parameter

Path parameters can be used to adapt and specify single operations. When creating a CRUD function, the path parameter "_id" is used by default. This parameter can be replaced with another property of a model. A path parameter corresponds to an equals query.The following property types are currently supported:

Type
Example
Description

Boolean

/persons/hasJob

Return all peoplewith a job. The Model Personcontains a boolean property called hasJob.

Text

/persons/name

Return all people with the same name. The Model Person contains a text property called name.

Enumeration

/persons/gender

Return all people with the same gender. The Model Person contains a reference to an Enum called gender.

Integer

/persons/age

Return all people within the same age. The Model Person contains an int property called age.

Float

/persons/money

Return all people within the same bank balance. The Model Person contains a float property called money.

Date

/persons/birthdate

Return all people within the same birthdate. The Model Person contains a date property called birthdate.

File

/person/profil_picture

Return a person with a certain profile picture. The Model Person contains a file property called profil_picture. The file _id needs to be used as the value here.

During the execution of the REST call, a value must be provided instead of the property:

Example:

# Give me all the people who are 24 years old.
/persons/24

Location is currently not supported.

At the current time, only one path parameter is allowed

Query Parameter

Query parameters are used as search criteria or filtering options. They allow users to dynamically modify the content they receive by including key-value pairs, like ?name="Stephen"&age=24, in the URL. At the moment, VisualBoost provides the nine different query operations, that can be specified in the Path input field of your CRUD function.

Operators:

Query
Operator
Example
Description

EQUAL

=

/persons?name=

NOT_EQUAL

!=

/persons?name!=

LOWER

<

/persons?age<

LOWER_THAN

<=

/persons?age<=

GREATER

>

/persons?name>

GREATER_THAN

>=

/persons?age>=

IN

.in()

/persons?age.in()

REGEX

.regex()

/persons?name.regex()

Only for text properties

NEAR

.near()

/persons?location.near()

Only for location properties

Static Values

Still in progress....

Extensions (Custom Functions)

VisualBoost makes it easy to customize your application and add your own business logic by allowing you to create Extensions. These Extensions are custom REST routes that can run their own unique functionality and are linked to specific models. For each model, you can add as many REST routes as you need. You can also synchronize these Extensions with VisualBoost, ensuring they fully integrate into your software architecture. Once synchronized, your Extensions will automatically be included in the documentation.

We recommend using the VisualBoost plugin to create extensions easily and comfortably.

Each Extension is part of a JavaScript file named after the corresponding model. To ensure it is recognized during synchronization, this file must be placed in the Extensions folder, which can be set in VisualBoost’s settings.

const router = require("express").Router();
const mongoose = require("mongoose");
const Person = require("../../db/generated/Person");

/**
 * Get a persons' name
 *
 * @name: getName
 *
 * @return: {
 *      name: String
 * }
 *
 * @errors: {
 *     400: "Bad Request",
 *     404: "Not found",
 *     500: "Internal Server Error"
 * }
 *
 **/
router.get("/person/name", async (req, res, next) => {

    return res.json({
        name: "John Doe"
    })

});

module.exports = router;

The example above demonstrates how to set up an extension. The main difference from a standard express route are the annotations within the comment block. These annotations help analyze the route during the synchronization process. Once analyzed, the route is integrated into the software architecture in VisualBoost. This ensures the architecture remains complete, even with custom business logic. Additionally, this feature can be reused for creating interface documentation and generating client code.

Annotations

VisualBoost provides 4 different annotations:

Annotation
Description
Available in HTTP Method

@name:

The functions name.

GET, POST, PUT, DELETE

@body:

The request body of the route.

POST, PUT, DELETE

@return:

The response body of the route.

GET, POST, PUT, DELETE

@errors:

The errors that can be thrown by the route.

GET, POST, PUT, DELETE

Annotation values:

The annotations @body and @return can be used to define the request and response bodies of a route. The following data types are supported:

Type
Description
Example

Boolean

Send or return a single boolean value

@return: Boolean

Int

Send or return a single integer value

@return: Int

Float

Send or return a single float value

@return: Float

String

Send or return a single string value

@return: Stringation

Date

Send or return a single date value

@return: Date

Location

Send or return a single location value (array with latitude and longitude)

@return: Location

Enumeration

Send or return a single enumeration value

@return: Gender(MALE, FEMALE)

Object

Send or return a single object

@return: {
     name: String,
     age: Int,
     address: {
         housenumber: Int,
         street: String,
         location: Location
      }
 }

Array

Send or return multiple values

Return an array of objects:

@return: [{
     name: String,
     age: Int,
     address: {
         housenumber: Int,
         street: String,
         location: Location
      }
 }]

Return an array of strings:

@return: [String]

The annotation for @errors requires the following structure:

@errors: {
     <http_status_1>: "<error_message_1>,
     <http_status_1>: "<error_message_2>
 }

Example:

@errors: {
    400: "Bad Request",
    404: "Not found",
    500: "Internal Server Error"
}

Be sure that the last error message does not end with a comma. If it does, the synchronization process may produce incorrect results.

Last updated