I'm working on improving an already existing API(Instagram) to level 3 in the Richardsons Maturity Model.
Basically, I want to include a uri to the resource in the API response.
Here is an example. This is a JSON representation of of a user resource.
{
"username": "emil",
"bio": "",
"website": "",
"profile_picture": "https://instagramimages-a.akamaihd.net/profiles/anonymousUser.jpg",
"full_name": "Yes",
"id": "1279132381"
}
As you can see, we get the id of this user. I then want to be able to include a uri to that resource in the JSON, like this.
{
"username": "emil",
"bio": "",
"website": "",
"profile_picture": "https://instagramimages-a.akamaihd.net/profiles/anonymousUser.jpg",
"full_name": "Yes",
"id": "1279132381",
"uri": "users/1279132381"
}
Here we have a URI to the user resource included in the response, this is want I want to be able to do.
I do not know where to start really. I can successfully utilize the Instagram API and get the original data but I don't know what to do next.
Suggestions on how I can accomplish this is greatly appreciated. I think there might be som kind of library to simplify this but I have not found anything yet.
I am developing in PHP using the Laravel framework.
Thank you!
Example in your case :
$arr = array(
'username' => "emil",
'bio' => "",
'website' => "",
'profile_picture' => "https://instagramimages-a.akamaihd.net/profiles/anonymousUser.jpg",
'full_name' => "Yes",
'id' => "1279132381"
);
$arr['uri'] = 'users/1279132381';
echo json_encode($arr);