Skip to content
This repository was archived by the owner on Jan 18, 2026. It is now read-only.

Express API

orl0pl edited this page Apr 7, 2023 · 5 revisions

ℹ️ Info

If you don't setted up, go back to home page and set up.

If something is not clear, create issue.

How to start

To start the server run:

npm run api-na

You will see:

📦Box master server is running at: http://localhost:939

To change the port modify the api.ts in api folder port variable (on line 12).

API endpoints:

GET /boxes

This endpoint returns an array of all the boxes in the database. You can also apply filters to the boxes by using query parameters. For example, to filter all boxes with the name "example", use the following endpoint:

GET /boxes?filter=name === 'example'

if you don't want to filter just use:

GET /boxes

GET /boxes/:id

This endpoint returns a single box with the specified ID.

POST /boxes/:id

This endpoint allows you to create, move, delete or edit a box. The :id parameter in the URL specifies the ID of the box to perform the action on. You need to provide a JSON payload in the request body with the following structure:

{   
"action": "create" | "move" | "delete" | "edit",   
"data": {     
  "attributes"?: object, // Only used when action is "create" or "edit"     
  "targetId"?: number | 'root' // Only used when action is "move"   
  } 
}

Creating a box

To create a box, set action to "create", and include an attributes object in the data field with the attributes for the new box. For example:

{   
  "action": "create",
  "data": {
    "attributes": {
       "name": "New box",
       "color": "blue"
     }   
  } 
}

This will create a new box with the name "New box" and the color "blue" as a child of the box with the specified :id.

Moving a box

To move a box, set action to "move", and include a targetId field in the data field with the ID of the new parent box. If you want to move the box to the root level, set targetId to "root". For example:

{
   "action": "move",
   "data": {
     "targetId": 3
   }
}

This will move the box with the specified :id to be a child of the box with ID 3.

Deleting a box

To delete a box, set action to "delete". For example:

{
   "action": "delete"
}

This will delete the box with the specified :id.

Editing a box

To edit a box, set action to "edit", and include an attributes object in the data field with the new attributes for the box. For example:

{
   "action": "edit",
   "data": {
     "attributes": {
       "name": "Updated box",
       "color": "red"
     }
   }
}

This will update the name and color of the box with the specified :id.

POST /boxes

This endpoint allows you to create a new box at the root level. You need to provide a JSON payload in the request body with the following structure:

{
   "action": "create",
   "data": {
     "attributes": object
   }
}

Include an attributes object in the data field with the attributes for the new box. For example:

{
   "action": "create",
   "data": {
     "attributes": {
       "name": "New box",
       "color": "blue"
     }
   }
}

This will create a new box with the name "New box" and the color "blue" at the root level.

Clone this wiki locally