How to make REST APIs for your app

In my project, besides the project manger role, I am also the one responsible for the backend implementation; In the project, the client and server are talking using the REST API; This is a simple note  about how to build the APIs for the client side;
Steps to make REST APIs
Steps to make REST APIs

Step 1: Understand the Requirement

First of all, we need to know what are the tasks want to be done by the client, which are the requirements; For example, getting the name of a place by giving the latitude and longitude;

You may need to collect the requirements from your users and verify with them;

This is an important step; If the understanding of the requirements is wrong, the following task will also be wrong and the final output will be wrong too.

Step 2: Design the API

In order to provide an API for client, we need to know the following things:

  • What will the API do ? (Example: getting some information, or update some value in the database?)
  • How many API need to be made to meet the requirements
  • What are the inputs and outputs
  • Are there any changes to the system after it is successfully done?
  • How will the client use this API?

Step 3: Implement the Backend Logic

After you have worked out step2, we are cleared that what are the inputs, outputs and the changes to the system, there will be enough information to work out the backend logics;

Here are some examples:

  •  Insert some records in database based on the input given by client side
  • Get a value from Database and pass to client side later

Step 4: Implement the API at the server side

When the backend logic ready, it will be ready to work out the REST API for the client;  There are several things need to be considered in this stage:

  • The format for data exchange, XML or JSON; Usually we will use JSON;
  • The way to pass the inputs; url parameter or a JSON message;
  • How to tell client if there is any error;

Here are some real examples:

Step 5: Testing the API using tools

When the API ready, before starting the client side coding, we should test the API; This step is very useful;  I always found problems of my APIs and fix them before working the Client side coding;

The simple tool to test the APIs are our browsers or command like curl; However these are not very user-friendly;

A tool called “POSTMAN (http://www.getpostman.com)” is recommended to use because it helps to organise the REST APIs well;

Step 6: Implement the API at the client side

In order to use the REST API easily, we need to make a set of client side API for other parts of the codes to call easily; The main work for this task is to marshal input to the server and demarshal the output returned from server; Also make tests to ensure the API work properly;

Here is a simple example from Google Map API:  Google Map Autocomplete for iOS : https://developers.google.com/places/ios/autocomplete

Conclusion

If you are making mobile app with a backend server supporting, you may need to build the REST APIs. Free feel to discuss what are the problems you are facing or share the tips to develop the APIs!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s