Format Json data yang akan di consume Mobile App.
Value untuk null
digantikan ke empty value untuk masing-masing tipe datanya.
Type | Acceptable Value | Empty Value (null) |
---|---|---|
string | "Lorem ipsum" "Dolor \nSit amet" |
"" |
integer | 42 -42 |
0 |
float | 1.234 -12.345 |
0 |
boolean | true false |
false |
object | {"lorem":"Lorem Ipsum", "dolor":"Dolor Sit Amet"} |
{} |
array | ["a", "b", "c"] [ 1, 2, 4, 5] |
[] |
array of object | [{"key":"Lorem Ipsum"}, {"key":"Dolor sit amet"}] [{"x":32, "y":23},{"x":10, "y":0},{"x":11, "y":11}] |
[] |
Sample code and message
code | message |
---|---|
404 | Not found |
204 | Success with no content |
Response tidak mengembalikan data pada json elemen 'data'(set ke empty object {}
)
{
"api_version": "2.0",
"memory_usage": "3.31MB",
"elapse_time": "6.267460107803345",
"lang": "id",
"currency":"IDR",
"error": {
"code": 404,
"message": "File Not Found",
"errors": [
{
"code": 3,
"reason": "ResourceNotFoundException",
"message": "File Not Found"
},{
"code": 7,
"reason": "Invalid format",
"message": "Format tanggal lahir salah"
}
]
},
"data": {}
}
{
"api_version": "2.0",
"memory_usage": "3.31MB",
"elapse_time": "6.267460107803345",
"lang": "id",
"currency":"IDR",
"error": {
"code": 299,
"message": "Expired Token",
"errors": []
},
"data": {
"updated": "2010-01-07T19:58:42.949Z",
"total_items": 800,
"start_index": 1,
"items_per_page": 1,
"items": [
{
"id": "hYB0mn5zh2c",
"uploaded": "2007-06-05T22:07:03.000Z",
"updated": "2010-01-07T13:26:50.000Z",
"title": "Google Developers Day US - Maps API Introduction",
"description": "Google Maps API Introduction ...",
"tags": [
"GDD07",
"GDD07US",
"Maps"
],
"thumbnail": {
"default": "http://i.ytimg.com/vi/hYB0mn5zh2c/default.jpg",
"hqDefault": "http://i.ytimg.com/vi/hYB0mn5zh2c/hqdefault.jpg"
},
}
]
}
}
Untuk response success, value untuk error
di set ke empty object {}
{
"api_version": "2.0",
"memory_usage": "3.31MB",
"elapse_time": "6.267460107803345",
"lang": "id",
"currency":"IDR",
"error": {},
"data": {
"updated": "2010-01-07T19:58:42.949Z",
"total_items": 800,
"start_index": 1,
"items_per_page": 1,
"items": [
{
"id": "hYB0mn5zh2c",
"uploaded": "2007-06-05T22:07:03.000Z",
"updated": "2010-01-07T13:26:50.000Z",
"uploader": "GoogleDeveloperDay",
"category": "News",
"title": "Google Developers Day US - Maps API Introduction",
"description": "Google Maps API Introduction ...",
"tags": [
"GDD07",
"GDD07US",
"Maps"
],
"thumbnail": {
"default": "http://i.ytimg.com/vi/hYB0mn5zh2c/default.jpg",
"hqDefault": "http://i.ytimg.com/vi/hYB0mn5zh2c/hqdefault.jpg"
}
}
]
}
}
{
"api_version": "2.0",
"memory_usage": "3.31MB",
"elapse_time": "1.23s",
"lang": "id",
"currency":"IDR",
"error": {
"code": 204,
"message": "no content",
"errors": []
},
"data": {}
}
<?php
$msc = microtime(true);
$temp_mmr = memory_get_usage();
try{
/*
your function start here
*/
$msc=microtime(true)-$msc;
$temp_mmr = memory_get_usage()-$temp_mmr;
$memoryusage = $this->memory_usage($temp_mmr);
//put $msc and $memoryusage in $response
$response = array( .... );
return Response::json($response); //this syntax is using laravel 4.2, kindly find in 5.^ if there is other syntax
}catch(Exception $e){
$msc=microtime(true)-$msc;
$temp_mmr = memory_get_usage()-$temp_mmr;
$memoryusage = $this->memory_usage($temp_mmr);
//put $msc and $memoryusage in $response
$response = array( .... ); //put hardcode response here with error code and error message that already agree with Mobile dev
return Response::json($response); //if using laravel 4.2 kindly find in 5.^ if there is other syntax
}
?>