RESTful API Tutorial

Kostya76

Regular Member
Joined
Dec 15, 2016
Messages
331
Reaction score
164
Hi there! I am not a coder, but I'm trying to understand how to use API's for a personal project I'm workign on.

I understand how to get data from the server using different parameters, but I can't understand how I can format the response in a way that would look good in a web page.

Can you guys recommend a good tutorial?
 
What type of format are you trying to achieve? I'm assuming you are using JSON for your API Responses

What i would recommend is this

Code:
{
  "status": true,
  "message": "success",
  "payload": { ... }
}

status => The status of the request, True if the request was successful, False if the user is missing a parameter or the request is invalid, etc.
message => The message if necessary, most cases you can set this to "success" if status is set to true, if status is set to false, explain why the request failed in this property.
payload => Your response data goes here, go wild. If the status is set to false, this payload should not be returned. and if there is no payload, don't even add it.
 
Search for postman, it 's free and you can send requests and get responses...what do you want to use for final script? I've tried python in pycharm because i can see responses as i go.
 
You need to look different things, firstly if the request is gonna be a POST or GET method.
Then you'll need to set the headers and the body parameters.

You do a call in php with the cURL, check it's documentation it's pretty easy.
Anyway after you sent the call, the website will respond in a JSON or XML format, you grab the result and put it inside an array.
After that the job is done you can do whatever you want to it !
 
Back
Top