In this tutorial we will cover:
- 1.Understanding JSONPlaceholder API
- 2.Dittofi Webservices
The API comes with eight API endpoints which it calls "Routes". These are shown below.
The Host will always remain the same. This is the address where the system we are connecting to is being hosted. But the Path will change, depending on which part of the system we are looking to access via the API Endpoints. For example, if we want to get the comments, we need to use the endpoint "GET /posts/1/comments".
Breaking down the URL here, we see again that we have:
Dittofi gives you the tools to connect to a third party API. To access these tools, go to the Web Services tab, under the tools icon.
Clicking on Web Services will bring up the following page.
To create a new web service (A) click "+ New Webservice" & (B) click "New Webservice".
This brings up a screen where you can configure your new webservice.
The screen is split into two parts. On the left hand side, you can specify the protocol that you will use to connect to the third party API. The options are HTTP & HTTPS. You can also enter the Host part of the URL that you're interested to connect to.
In our case we want to connect to the JSONPlaceholder API. Reading their website, we can see that their API supports either HTTP or HTTPS & we already know that the Host is jsonplaceholder.typicode.com. So we configure our webservice in the following way & press save.
Next, we can turn our attention to the right hand side of the screen.
This is where we are going to add the different API endpoints that we are going to connect to. For example "GET /posts", "GET /posts/1/comments", "GET /comments?postsid=1" etc.
To begin with, let's add the "GET /posts" endpoint. To do this, we must begin by configuring the "Basic" settings of our webservice as below.
The grid below explains what each of the options are.
In the example above, we have not yet created a our Resp. Variable (response variable). To do this, head on over to the Custom Models tab. This can be found below the tools icon in the toolbar.
Clicking on Custom Models brings us to the Custom Models tab, as below.
Inside the Custom Models tab, you're able to build or generate custom data structures that can be used to store data temporarily. In our case we want to take the data that will be returned from the JSONPlaceholder API & stick it into a variable.
To generate a custom model to map your data into, you can use the following 5 steps, starting from Generating the model through to inspecting the new Custom Model.
Next, we step back to the Webservice tab & set the response variable for our API Endpoint to equal our new custom model.
Ditto Tip: Notice, we set the Kind to Collection (custom model). This is because we are expecting a list of JSON objects back from the API when we request the data. Collections inside Dittofi are like lists.
Press save & the API Endpoint has been setup.
To test the API Endpoint, we can create our own endpoint, action & event to run an HTTP request. The video below shows this happening.