-
Notifications
You must be signed in to change notification settings - Fork 0
REST API
###Wstęp API przygotowanego projektu opiera się o powszechnie stosowane praktyki REST'owe. Statusy wiadomości HTTP zwracane w podstawowych przypadkach są zgodne z przyjętymi standardami. Więcej na temat standardów można doczytać na stronie: http://www.restapitutorial.com/lessons/httpmethods.html.
Autoryzacja i uwierzytelnianie opiera się o BASIC.
Jako standard formatowania wiadomości wykorzystywany jest JSON + HAL.
#####Reagowanie na błędy logiki biznesowej
W niektórych sytuacjach istnieje potrzeba przesłania dodatkowych informacji na temat przyczyny błędu. Informację te są zawarte w prezentowanej niżej strukturze.
Przykład odpowiedzi na błędny request:
{
"message":"Nie można usunąć pomiaru złożonego, ponieważ jest on wykorzystywany w systemie przez inny pomiar"
}###Katalog
| id | zasób | opis |
|---|---|---|
| [[RST_KT_MSL | REST-API#rst_kt_msl]] | GET measurements |
| [[RST_KT_MSA | REST-API#rst_kt_msa]] | POST measurements |
| [[RST_KT_MSG | REST-API#rst_kt_msg]] | GET measurements/{id} |
| [[RST_KT_MSD | REST-API#rst_kt_msd]] | DELETE measurements/{id} |
| [[RST_KT_MSSP | REST-API#rst_kt_mssp]] | GET measurements/filter |
| [[RST_KT_RSL | REST-API#rst_kt_rsl]] | GET resources |
###Monitor
| id | zasób | opis |
|---|---|---|
| [[RST_MT_MSL | REST-API#rst_mt_msl]] | GET measurements |
| [[RST_MT_CMSA | REST-API#rst_mt_cmsa]] | POST measurements/{id} |
| [[RST_MT_MSG | REST-API#rst_mt_msg]] | GET measurements/{id} |
| [[RST_MT_MSVL | REST-API#rst_mt_msvl]] | GET measurements/{id}/data |
| [[RST_MT_CMSD | REST-API#rst_mt_cmsd]] | DELETE measurements/{id} |
| [[RST_MT_MSSP | REST-API#rst_mt_mssp]] | GET measurements/filter |
| [[RST_MT_RSL | REST-API#rst_mt_rsl]] | GET resources |
######Zasób URL GET measurements
######Przykład
Odpowiedz serwera:
{
"_links" : {
"filter" : {
"href" : "http://127.0.0.1:8080/measurements/filter"
}
},
"_embedded" : {
"measurements" : [ {
"resource" : "memUsage",
"metric" : "host",
"_links" : {
"self" : {
"href" : "http://127.0.0.1:8080/measurements/359a2051-ab94-40f6-b89a-f4ffec4da2a7"
},
"details" : {
"href" : "http://127.0.0.1:8081/measurements/359a2051-ab94-40f6-b89a-f4ffec4da2a7"
}
}
}, {
"resource" : "cpuUsage",
"metric" : "host",
"_links" : {
"self" : {
"href" : "http://127.0.0.1:8080/measurements/c40fac9f-8c96-4476-b435-aa52e4b17e08"
},
"details" : {
"href" : "http://127.0.0.1:8081/measurements/c40fac9f-8c96-4476-b435-aa52e4b17e08"
}
}
}, {
"resource" : "memUsage",
"metric" : "zeus_cpu_1B",
"_links" : {
"self" : {
"href" : "http://127.0.0.1:8080/measurements/bffb94a2-2152-4559-992e-f9348da19619"
},
"details" : {
"href" : "http://127.0.0.1:8081/measurements/bffb94a2-2152-4559-992e-f9348da19619"
}
}
} ]
}
}######Zasób URL POST measurements
######Przykład
Wiadomość:
{
"monitor": "192.168.0.22",
"resource": "Host",
"metric": "CPU"
}######Zasób URL GET measurements/{id}
######Przykład Odpowiedz serwera:
{
"resource" : "memUsage",
"metric" : "host",
"_links" : {
"self" : {
"href" : "http://127.0.0.1:8080/measurements/359a2051-ab94-40f6-b89a-f4ffec4da2a7"
},
"details" : {
"href" : "http://127.0.0.1:8081/measurements/359a2051-ab94-40f6-b89a-f4ffec4da2a7"
}
}
}######Zasób URL DELETE measurements/{id}
######Zasób URL GET measurements/filter
######Parametry Wymagane jest aby przynajmniej jeden parametr był podane w adresie
- resource - nazwa zasobu po którym chcemy filtrować
- metric - nazwa metryki po której chcemy filtrować
######Przykład
Adres URL: measurements/filter?metric=host Odpowiedz serwera:
{
"_embedded": {
"measurements": [
{
"resource": "memUsage",
"metric": "host",
"_links": {
"self": {
"href": "http://127.0.0.1:8080/measurements/359a2051-ab94-40f6-b89a-f4ffec4da2a7"
},
"details": {
"href": "http://127.0.0.1:8081/measurements/359a2051-ab94-40f6-b89a-f4ffec4da2a7"
}
}
},
{
"resource": "cpuUsage",
"metric": "host",
"_links": {
"self": {
"href": "http://127.0.0.1:8080/measurements/c40fac9f-8c96-4476-b435-aa52e4b17e08"
},
"details": {
"href": "http://127.0.0.1:8081/measurements/c40fac9f-8c96-4476-b435-aa52e4b17e08"
}
}
}
]
}
}######Zasób URL GET resources
######Przykład Odpowiedz serwera:
{
"_embedded": {
"resources": [
{
"name": "memUsage",
"_links": {
"measurements": {
"href": "http://127.0.0.1:8080/measurements/filter?resource=memUsage"
}
}
},
{
"name": "cpuUsage"
"_links": {
"measurements": {
"href": "http://127.0.0.1:8080/measurements/filter?resource=cpuUsage"
}
}
}
]
}
}###Monitor
######Zasób URL GET measurements
######Przykład Odpowiedz serwera:
{
"_links" : {
"filter" : {
"href" : "http://monitor1/measurements/filter"
}
},
"_embedded" : {
"measurements" : [ {
"resource" : "cpuUsage",
"metric" : "host",
"unit": "%",
"_links" : {
"self" : {
"href" : "http://monitor1/measurements/c40fac9f-8c96-4476-b435-aa52e4b17e08"
},
"data" : {
"href" : "http://monitor1/measurements/c40fac9f-8c96-4476-b435-aa52e4b17e08/data"
}
}
}, {
"resource" : "memUsage",
"metric" : "zeus_cpu_1B",
"unit": "%",
"_links" : {
"self" : {
"href" : "http://monitor1/measurements/bffb94a2-2152-4559-992e-f9348da19619"
},
"data" : {
"href" : "http://monitor1/measurements/bffb94a2-2152-4559-992e-f9348da19619/data"
}
}
} ]
}
}######Zasób URL POST measurements/{id}
######Przykład Wiadomość:
{
"type" : "mean",
"params": [5,1]
}
######Zasób URL DELETE measurements/{id}
######Zasób URL GET measurements/{id}
######Przykład Odpowiedz serwera:
{
"resource": "cpuUsage",
"metric": "host",
"unit": "%",
"_links": {
"self": {
"href": "http://monitor1/measurements/c40fac9f-8c96-4476-b435-aa52e4b17e08"
},
"data": {
"href": "http://monitor1/measurements/c40fac9f-8c96-4476-b435-aa52e4b17e08/data"
}
}
}######Zasób URL GET measurements/{id}/data
######Parametry
- limit - określa czy ograniczyć dane do jednego rekordu. Możliwe wartości all lub last [ domyślna wartość ]
######Przykład Adres URL: GET measurements/f621a2b0-b76b-11e3-a5e2-0800200c9a62/data?limit=all Odpowiedz serwera:
{
"_embedded": {
"data": [
{
"timestamp": 1398071005,
"data": 30
},
{
"timestamp": 1398072005,
"data": 76
},
{
"timestamp": 1398075305,
"data": 34
}
]
}
}Adres URL: GET measurements/f621a2b0-b76b-11e3-a5e2-0800200c9a66/data?limit=last Odpowiedz serwera:
{
"_embedded": {
"data": [
{
"timestamp": 1398071605,
"data": 30
}
]
}
}######Zasób URL GET measurements/filter
######Parametry Wymagane jest aby przynajmniej jeden parametr był podane w adresie
- resource - nazwa zasobu po którym chcemy filtrować
- metric - nazwa metryki po której chcemy filtrować
######Przykład
Adres URL: measurements/filter?metric=host
{
"_embedded": {
"measurements": [
{
"resource": "memUsage",
"metric": "host",
"_links": {
"self": {
"href": "http://127.0.0.1:8081/measurements/359a2051-ab94-40f6-b89a-f4ffec4da2a7"
}
}
},
{
"resource": "cpuUsage",
"metric": "host",
"_links": {
"self": {
"href": "http://127.0.0.1:8081/measurements/c40fac9f-8c96-4476-b435-aa52e4b17e08"
}
}
}
]
}
}######Zasób URL GET resources
######Przykład Odpowiedz serwera:
{
"_embedded": {
"resources": [
{
"name": "memUsage",
"_links": {
"measurements": {
"href": "http://127.0.0.1:8081/measurements/filter?resource=memUsage"
}
}
},
{
"name": "cpuUsage",
"_links": {
"measurements": {
"href": "http://127.0.0.1:8081/measurements/filter?resource=cpuUsage"
}
}
}
]
}
}