Commit 9f705f53 authored by José San Juan's avatar José San Juan

Add new file

parents
Remote Power API v.2.0
===
This document describes the JSON api of Remote Power Service.
## Authentication
Authentication is mandatory to access to the Json api. We provide two authentication methods:
Basic Http Authentication and JWT Authentication.
### JWT Token authentication
To access to the api using this method, you only need to add the Authentication Http header with a valid token. This token is a standard JWT token encoded with HS256 method and signed.
```
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJjcmVhdGVkIjoxNDc1...
```
---
## Switches End Point
### Get the status of all switches
### Request
**URL:** api/v1/switches
**Method:** GET
**Accepts:** application/json
#### Success Response:####
**Code:** 200 OK
**Payload:**
```javascript
[
{
"acronym": "PRMPW_GIANO_GUIDER",
"status": "OFF"
},
{
"acronym": "PRMPW_DERA_ADOPTCCD",
"status": "OFF"
},
{
"acronym": "PRMPW_DERB_VMERAB",
"status": "OFF"
}, ...
```
---
### Get the status of one switch by his name
#### Request
**URL:** api/v1/switches/[SWITCH_NAME]
**Method:** GET
**Accepts:** application/json
#### Success Response:
**Code:** 200 OK
**Payload:**
```javascript
{
"acronym": "SWITCH_NAME",
"status": "OFF"
}
```
#### Error Response:
**Code:** 404 Not found
**Content:**
```javascript
{
"timestamp": 1475150138186,
"status": 404,
"error": "Not Found",
"exception": "es.iac.tng.services.remotepower.api.exceptions.ElementNotFoundException",
"message": "Could not find ERROR_SWITCH_NAME",
"path": "/remotepower/api/v1/switches/ERROR_SWITCH_NAME"
}
```
---
### Set the status of one or multiple switches ###
#### Request ####
**URL:** api/v1/switches/
**Method:** POST
**Accepts:** application/json
**Content-Type:** application/json;charset=UTF-8
**Payload:**
```javascript
[
{
"acronym": "SWITCH_NAME_1",
"status": "ON"
},
{
"acronym": "SWITCH_NAME_2",
"status": "OFF"
},
]
```
#### Success Response:
**Code:** 200 OK
**Payload:**
```javascript
[
{
"acronym": "SWITCH_NAME_1",
"status": "ON"
},
{
"acronym": "SWITCH_NAME_2",
"status": "OFF"
},
]
```
#### Error Response:
**Reason:** The switch don't exits or incorrect switch name. If the request is a multiple command will not act on any switch.
**Code:** 404 Not found
**Content:**
```javascript
{
"timestamp": 1475150138186,
"status": 404,
"error": "Not Found",
"exception": "es.iac.tng.services.remotepower.api.exceptions.ElementNotFoundException",
"message": "Could not find ERROR_SWITCH_NAME",
"path": "/remotepower/api/v1/switches/"
}
```
**Reason:** Malformed payload or execution error of one command. The message contains all the details about the error.
**Code:** 500 Internal Server Error
**Content:**
```javascript
{
"timestamp": 1475150924630,
"status": 500,
"error": "Internal Server Error",
"exception": "es.iac.tng.services.remotepower.api.exceptions.CommandErrorException",
"message": "Command error: Unexpected character...",
"path": "/remotepower/api/v1/switches/"
}
```
## Devices End Point
### Get the status of the devices thats handle the switches
### Request
**URL:** api/v1/devices
**Method:** GET
**Accepts:** application/json
#### Success Response:####
**Code:** 200 OK
**Payload:**
```javascript
[
{
"acronym": "pwrctrl_14",
"connected": true,
"deviceTemperature": 22.064226,
"mockDevice": true
},
{
"acronym": "rab_211_0",
"connected": true,
"mockDevice": true
}...
```
---
### Get the status of one device by his name
#### Request
**URL:** api/v1/devices/[DEVICE_NAME]
**Method:** GET
**Accepts:** application/json
#### Success Response:
**Code:** 200 OK
**Payload:**
```javascript
{
"acronym": "DEVICE_NAME",
"connected": true,
"mockDevice": true
}
```
#### Error Response:
**Code:** 404 Not found
**Content:**
```javascript
{
"timestamp": 1475152667716,
"status": 404,
"error": "Not Found",
"exception": "es.iac.tng.services.remotepower.api.exceptions.ElementNotFoundException",
"message": "Could not find DEVICE_NAME",
"path": "/remotepower/api/v1/devices/DEVICE_NAME"
}
```
---
### Set the status of one or multiple devices ###
#### Request ####
**URL:** api/v1/devices/
**Method:** POST
**Accepts:** application/json
**Content-Type:** application/json;charset=UTF-8
**Payload:**
```javascript
[
{
"acronym": "DEVICE_NAME_1",
"connected": false,
},
{
"acronym": "DEVICE_NAME_2",
"status": "true"
}
]
```
#### Success Response:
**Code:** 200 OK
**Payload:**
```javascript
[
{
"acronym": "DEVICE_NAME_1",
"connected": false,
},
{
"acronym": "DEVICE_NAME_2",
"status": "true"
}
]
```
#### Error Response:
**Reason:** The device don't exits or incorrect device name. If the request is a multiple command will not act on any switch.
**Code:** 404 Not found
**Content:**
```javascript
{
"timestamp": 1475152667716,
"status": 404,
"error": "Not Found",
"exception": "es.iac.tng.services.remotepower.api.exceptions.ElementNotFoundException",
"message": "Could not find DEVICE_NAME",
"path": "/remotepower/api/v1/devices/DEVICE_NAME"
}
```
**Reason:** Malformed payload or execution error of one command. The message contains all the details about the error.
**Code:** 500 Internal Server Error
**Content:**
```javascript
{
"timestamp": 1475150924630,
"status": 500,
"error": "Internal Server Error",
"exception": "es.iac.tng.services.remotepower.api.exceptions.CommandErrorException",
"message": "Command error: Unexpected character...",
"path": "/remotepower/api/v1/devices/"
}
```
---
## Server Send Events End Point
### Subscribe to service update events
### Request
**URL:** api/v1/updates
**Method:** GET
**Accepts:** application/json
#### Success Response:####
**Code:** 200 OK
**Content-Type:** text/event-stream;charset=UTF-8
**Payload:**
```javascript
event:switch
data:{"acronym":"PRMPW_GIANO_TIPTILT","status":"ON"}
event:device
data:{"acronym": "pwrctrl_14", "connected": true, "deviceTemperature": 22.064226, "mockDevice": true }
...
```
---
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment