Standar Reponse API Talaria
===
### STANDAR RESPON API TALARIA
#### Format JSON API
Format standar respon API Talaria menggunakan JSON (https://tools.ietf.org/html/rfc7159)
Parameter standar respon antara lain:
* code -- kode respon bisa dikustom (dibuatkan daftar kode)
* status -- status respon [SUCCESS, ERROR, EMPTY, NOAKSES, LAIN]
* message -- pesan respon bisa dikustom (pesan server diteruskan ke client)
* data -- data tambahan dari respon
* version -- berisikan data versi dari app
#### Contoh format respon:
#### 1. RESPON GET (2XX)
1.1 Format respon GET (status: SUKSES)
```
HTTP/1.1 200
Content-Type: application/json
{
"response": {
“code”: “20000000”
“status”: “SUCCESS”
“message”: “sukses get data berita”
},
“data”: [
{“key1”:”value1”},
{“key2”: “value2”}
],
"properties" : {
"image" : "response.jpg",
"icon" : "ic_respnse.png",
"title" : {
"caption" : "Tes"
},
"button" : {
"title" : "Tes",
"color" : "#34432",
"event" : {
"binding" : "click",
"name" : "function name"
}
},
"action" : {
"title" : "Tes",
"type" : "button/link",
"url" : "http://"
},
"success" : {
"type" : "form/response",
"id" : "email"
},
"error" : {
"type" : "form/response",
"id" : "email"
}
}
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
1.2 Format respon GET (status: EMPTY)
```
HTTP/1.1 200
Content-Type: application/json
{
"response": {
“code”: “20000000”
“status”: “EMPTY”
“message”: “data akun tidak ditemukan”
},
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
| CODE | STATUS | MESSAGE(dapat diganti) |
| -------- | -------- | -------- |
| 20000000 | SUCCESS | Text |
| 20000000 | EMPTY | Status Empty
#### 2. RESPON POST (2XX)
2.1 Format Respon POST (status: SUKSES)
```
HTTP/1.1 200
Content-Type: application/json
{
"response": {
“code”: “20000000”
“status”: “SUCCESS”
“message”: “sukses post data pengaduan”
}
“data”: {
“nopengaduan”: “000AA123”
},
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
```
HTTP/1.1 200
Content-Type: application/json
{
"response": {
“code”: “20000000”
“status”: “SUCCESS”
“message”: “sukses post data pengaduan”
}
“data”: [
{“key1”:”value1”},
{“key2”: “value2”}
],
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
2.2 Format Respon POST (status: EMPTY)
```
HTTP/1.1 200
Content-Type: application/json
{
"response": {
“code”: “20000000”
“status”: “EMPTY”
“message”: “data akun tidak ditemukan”
},
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
| CODE | STATUS | MESSAGE |
| -------- | -------- | -------- |
| 20000000 | SUCCESS | Status Sukses |
| 20000000 | EMPTY | Status Empty
#### 3. RESPON PUT (2XX)
3.1 Format Respon PUT (status: SUKSES)
```
HTTP/1.1 200
Content-Type: application/json
{
"response": {
“code”: “20000000”
“status”: “SUCCESS”
“message”: “sukses post data pengaduan”
}
“data”: {
“nopengaduan”: “000AA123”
},
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
```
HTTP/1.1 200
Content-Type: application/json
{
"response": {
“code”: “20000000”
“status”: “SUCCESS”
“message”: “sukses post data pengaduan”
}
“data”: [
{“key1”:”value1”},
{“key2”: “value2”}
],
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
3.2 Format Respon POST (status: EMPTY)
```
HTTP/1.1 200
Content-Type: application/json
{
"response": {
“code”: “2000000”
“status”: “EMPTY”
“message”: “data akun tidak ditemukan”
},
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
#### 4. RESPON 4xx
4.1 Format Respon 401 Unauthorized
```
HTTP/1.1 401
Content-Type: application/json
{
"response": {
“code”: “40100000”
“status”: “UNAUTHORIZED”
“message”: “status unauthorized”
},
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
4.2 Format Respon 403 Forbidden
```
HTTP/1.1 403
Content-Type: application/json
{
"response": {
“code”: “40300000”
“status”: “FORBIDDEN”
“message”: “status forbidden”
},
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
4.3 Format Respon 404 Not Found
```
HTTP/1.1 404
Content-Type: application/json
{
"response": {
“code”: “40400000”
“status”: “NOTFOUND”
“message”: “status not found”
},
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
4.4 Format Respon 408 Request Timeout
```
HTTP/1.1 408
Content-Type: application/json
{
"response": {
“code”: “40800000”
“status”: “TIMEOUT”
“message”: “request time out”
},
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
4.5 Format Respon 429 Too Many Request
```
HTTP/1.1 429
Content-Type: application/json
{
"response": {
“code”: “42900000”
“status”: “TOOMANY”
“message”: “request too many”
},
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
#### 5. RESPON 5XX
5.1 Format Respon 500 Server Error
```
HTTP/1.1 500
Content-Type: application/json
{
"response": {
“code”: “50000000”
“status”: “SERVERERROR”
“message”: “server error”
},
"version" : {
"app" : "ether V1.2.0",
"build" : "ether-canopus B1.2.1-05052020"
"date" : "05 Mei 2020"
}
}
```
| CODE | STATUS | MESSAGE(dapat diganti) |
| -------- | -------- | -------- |
| 40100000 | UNAUTHORIZED | Status Unauthorized |
| 40300000 | FORBIDDEN | Status Forbidden
| 40400000 | NOTFOUND | Status Not Found
| 42900000 | TOOMANY | Request too many
| 50000000 | ERROR | Status Server Error
### Tabel Standar Response
#### Keterangan Status
| STATUS | KETERANGAN |
| -------- | -------- |
| SUCCESS | data ditemukan |
| EMPTY | data kosong |
| UNAUTHORIZED | token/user&password tidak valid |
| FORBIDDEN | user tidak ada akses |
| NOTFOUND | halaman tidak ditemukan |
| TOOMANY | terlalu banyak akses |
| INVALID | parameter request kosong/tidak valid |
| ERROR | ketika server/aplikasi error |
#### Standar Code
| CODE | STATUS | MESSAGE(dapat diganti) |
| -------- | -------- | -------- |
| 20000000 | SUCCESS | Status Sukses |
| 20000030 | EMPTY | Pelanggan Tidak ditemukan |
| 20000031 | EMPTY | Pelanggan Tidak aktif |
| 20000000 | EMPTY | Status Empty |
| 40000000 | INVALID | Status Invalid Parameter |
| 40100000 | UNAUTHORIZED | Status Unauthorized |
| 40300000 | FORBIDDEN | Status Forbidden|
| 40400000 | NOTFOUND | Status Not Found|
| 42900000 | TOOMANY | Request too many |
| 50000000 | ERROR | Status Error |
Referensi:
https://github.com/cryptlex/rest-api-response-format
https://jsonapi.org/format/
https://medium.com/@bojanmajed/standard-json-api-response-format-c6c1aabcaa6d
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes