In part12 we have our interface and API end-points implemented. In addition we tested API end-points with web browser and received response from API end-points successfully. However our API end-points was implemented with either get method or post method and now we need to test API end-points implemented with post method.
Postman is a free tool which allow us to test API end-points in our backend server easily. Moreover it support Windows, MacOSX and Linux operating system.
We will use winemag-data-130k-v2.csv dataset for machine learning.
Head to Postman website and download Postman app for your operating system. And sign up for an account.
Now open your Postman app after installation and you will see following screen.
Select Collections under your workspace on left. If there is no workspace you can create a new workspace with button New. On the right side of screen is where your do your API end-points testing.
Similar to web browser, you can create a new task with button + on top. In each task your can send a request to an API end-point and receive a response.
Test root URL
First create a new task if you haven’t. Enter your root URL in URL input field and make sure method dropdown selection on left is GET. Click button Send. Postman will make a request with get to the URL and receive a response from server shortly.
You can see the detail of response at bottom.
If you can’t see the response then make sure you have Body and Pretty selected.
Body: the body of response and usually in form of JSON or XML
Headers: the header of response
Pretty: allow you to see the body from response in a much easier format
Test URL with parameters
Let’s make a request to see all wine titles. We have implemented API end-point.
Its URL is
First create a new task if you haven’t. Enter your sub domain URL in URL input field and make sure method dropdown selection on left is GET. Click button Send. Replace Root URL to yours and parameter to title since we are querying all titles i.e
http://[your Root URL]/list-of/title .
This sub domain URL also take page and size as well. Let’s add them. Under URL input field, select Params section and enter page and size for key and their values in this case I use 40 for size and 1 for page. it means to show first page of result and display them as 40.
page and size are query parameters while title is URL parameter
In the response, we can see that it is first page and result is 40 wine titles in a list. In addition it give us total pages and results. You can play around page and size to see the different outcome.
Wine data is a tubular form rows and column. Now we only queried all titles from title column but there are more columns we can queried from.
To see the number of column name available, we can make a new request to API end-point to see.
Similar to previous requests we can replace sub domain URL with
In the response, we can see there are number of column name we can query. You can just replace title from previous example with any of this name.
For example, I pick country and I will receive the following.
Test API end-points with post
It is straightforward to test API end-point with post. Let’s take API end-point
http://[Root URL]/find-wine for example.
The URL expect user to give wine_query data which is description of taste of a particular wine as text then response with recommendation of wines.
Say we have a description of taste “The creamy palate delivers apple, nut, spice, thyme and sage along with fine, persistent effervescence.”
All you need to do is add a JSON data to the request’s body. The data which contain key description and its value which is our description of taste.
With get method we can also add query parameters
The recommendation system find all wines similar to our description. In this example wine “Bellavista 2006 Gran Cuvée Pas Operé Sparkling (Franciacorta)” has certain part of its description I wrote and it is included in the list.
The model take our description and compare it to what it had learned by using similarity.
https://www.vivino.com/ a site that you can find wine and review from different people.
Postman make our life much easier for testing our API end-points.
With get method we can pass URL parameter with query parameters.
With post method we can pass data as JSON in the request’s body. In addition we can add query parameters as well.
Once we are sure our model and API end-points are ready then we can deploy them to live server such as Heroku.