# 🚀 EatUp Setup Server
Here you will find the documentation of the setup_server microservice of the EatUp project.
## 📡 Status: `/api/v1`
All the logic to handle the status of the project. Implemented as a finite state machine.
GET /api/v1/status
Get the status of the project.
Examples
### The project is not installed nor created.
```javascript
fetch("/api/v1/api/v1/status", {
method: "GET",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
200
"not_created"
```
### The project is created but not installed.
```javascript
fetch("/api/v1/api/v1/status", {
method: "GET",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
200
"created"
```
### The project is created and installed.
```javascript
fetch("/api/v1/api/v1/status", {
method: "GET",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
200
"installed"
```
POST /api/v1/create
Creates the project. It can only be called if the project is not created.
Examples
### The project is not created.
```javascript
fetch("/api/v1/api/v1/create", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
200
```
### The project has already been created.
```javascript
fetch("/api/v1/api/v1/create", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
409
Project already created
```
POST /api/v1/install
Installs the project. Creates the database. It can only be called if the project is created.
Examples
### The project is created.
```javascript
fetch("/api/v1/api/v1/install", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(
{
"db_usr": "XXXXXX",
"db_usr_passwd": "YYYYYY",
"server_port": ZZZZZZ
}
)
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
200
```
### The project is not created.
```javascript
fetch("/api/v1/api/v1/install", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
409
Project not created
```
### The project is already installed.
```javascript
fetch("/api/v1/api/v1/install", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
409
Project already installed
```
POST /api/v1/uninstall
Uninstalls the project. Can be called at any time.
Examples
### Uninstalling the project.
```javascript
fetch("/api/v1/api/v1/uninstall", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
200
```
## 📡 Microservices: `/api/v1/microservices`
Logic to handle the microservices of the project.
GET /api/v1/microservices
Get the state of all microservices.
Examples
### Get the state of all microservices of a not installed project.
```javascript
fetch("/api/v1/microservices/api/v1/microservices", {
method: "GET",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
200
[
{
"id": null,
"name": "YYYYYY",
"state": "ZZZZZZ"
"ip": null,
"port": null
},
...
]
```
### Get the state of all microservices of an installed project.
```javascript
fetch("/api/v1/microservices/api/v1/microservices", {
method: "GET",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
200
[
{
"id": "XXXXXX",
"name": "YYYYYY",
"state": "ZZZZZZ"
"ip": "AAAAAA",
"port": BBBBBB
},
...
]
```
POST /api/v1/microservices/start/:microservice_name
Starts a microservice.
### Parameters
| Name | Example | Description |
| ---- | --- | --- |
| `microservice_name` | `.../eatup_db/...` | The name of the microservice to start. |
Examples
### Start DB of a not installed project.
```javascript
fetch("/api/v1/microservices/api/v1/microservices/start/eatup_db", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
409
Invalid action start for eatup_db
```
### Start DB of an installed project.
```javascript
fetch("/api/v1/microservices/api/v1/microservices/start/eatup_db", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
200
```
### Start DB when it is already running.
```javascript
fetch("/api/v1/microservices/api/v1/microservices/start/eatup_db", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
409
Invalid action start for eatup_db
```
### Start the server when DB is not running.
```javascript
fetch("/api/v1/microservices/api/v1/microservices/start/eatup_server", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
409
Invalid action start for eatup_server
```
### Start a microservice that does not exist.
```javascript
fetch("/api/v1/microservices/api/v1/microservices/start/invalid_microservice", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
409
This container does not exist or belong to this project.
```
POST /api/v1/microservices/stop/:microservice_name
Stops a microservice.
### Parameters
| Name | Example | Description |
| ---- | --- | --- |
| `microservice_name` | `.../eatup_db/...` | The name of the microservice to stop. |
Examples
### Stop DB of a not installed project.
```javascript
fetch("/api/v1/microservices/api/v1/microservices/stop/eatup_db", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
409
Invalid action stop for eatup_db
```
### Stop DB of an installed project.
```javascript
fetch("/api/v1/microservices/api/v1/microservices/stop/eatup_db", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
200
```
### Stop server when it is already stopped and DB is stopped.
```javascript
fetch("/api/v1/microservices/api/v1/microservices/stop/eatup_server", {
method: "POST",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
409
Invalid action stop for eatup_server
```
## 📡 Special requests: `/`
This section contains the documentation for the special requests
GET /
Ping request to check if the server is up
Examples
### Ping the server
```javascript
fetch("/", {
method: "GET",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
This is the result
```json
200
"eatup_setup_server up and running!"
```
OPTIONS /*
CORS preflight request.
Examples
### CORS preflight request
```javascript
fetch("//", {
method: "OPTIONS",
})
.then(response => response.json()) // If valid
//.then(response => response.text()) // If invalid
.then(json => console.log(json));
.catch(error => console.error(error));
```
Response:
```json
204
```
🔧 Details
## Legend
This are the meanings of the symbols used in this document
| Element | Meaning |
| ------- | ------- |
| `XXXXXX` | Some value that would be replaced for something else in the real situation. |
| `...` | More parameters can be added to the request |
## API Codes
| Code | Meaning | Description |
| ---- | ------- | ----------- |
| `200` | *200 OK* | The request was successful. |
| `204` | *204 No Content* | The request was successful, but there is no content to return. Used for CORS preflight requests. |
| `404` | *404 Not Found* | The resource does not exist. |
| `409` | *409 Conflict* | Something is not right with the request. |
| `500` | *500 Internal Server Error* | Something went wrong on the server. Please contact with the administrator. |
| `501` | *501 Not Implemented* | The endpoint is not implemented yet. |
## Legend
This are the available states of a microservice
| Element | Meaning |
| ------- | ------- |
| `Created` | The microservice has been created, but not started. |
| `Running` | The microservice is running. |
| `Restarting` | The microservice is restarting. |
| `Exited` | The microservice has exited. |
| `Paused` | The microservice is paused. |
| `Dead` | The microservice is dead. |
| `NotFound` | The microservice container does not exist. |
Made with ❤️ using [api_docs_generator](https://github.com/Jkutkut/rust-api_docs_generator) v0.7.0.