Calling API methods
Many projects are prepared as distributed systems with not only mobile applications. Very often, a set of web applications is used as well, for example, to enter data by users. Of course, such data also needs to be shown in mobile applications along with the possibility of updating them just after modification in the web-based part. What is more, some external data, for example, obtained from the sensors of mobile devices, may need to be entered into the system. These are only a few reasons why APIs are developed as a way of exchanging data between various parts of the system. In this chapter, you will learn how to send GET and POST-based requests to the API and obtain JSON-encoded results.
As an example, you will create the page that contains two buttons and a text block for presenting the results. After clicking on the first button, the GET request will be sent to the API. As a result, the JSON-encoded data of users will be returned. Then, the number of users, together...