GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.thunkable.com — Web APIs Blocks | Thunkable Docs OverviewGreat data is an essential part of many apps built today and the Web API component enables apps to retrieve data from any public or private API (application programming interface) service on the web. For more advanced developers who have write access to a private API, this component also enables you to upload and delete data. To see what public APIs are available, we recommend this list from Todd Motto. Video TutorialHow to Connect Your Thunkable App to a Web APIIn this tutorial, you’ll learn what an API is, connect a Thunkable project to a web API, retrieve and parse the relevant data from the API, and use Thunkable blocks to modify the API URL that is called. Add a Web API to Your AppTo add a Web API component to your app:
A Web API component properties dialog launches. See the chart below for descriptions of the various properties. Click Submit to create the Web API component, or Delete to dismiss the dialog without creating the component. Once you have the API key, you'll need to enter the unique URL into the property field of the Web API component. Property Description Required? URL The url for the web request which usually contains an API key Required QueryParameters Specifies some parameters of the data Optional Body Body of your API call. Select from String or Multipart Form Data. Optional Headers Specifies some meta-data, eg: usernames and passwords Optional ![]() Edit properties of your Web APIOnce you have added at least one Web API component to your app, you will be able to view all of your Web API components under the To edit the properties of a Web API component, click on the ⚙ icon next to the component's name to bring up the properties dialog. You will be able to change the properties and click Submit to save your changes, or click Delete to delete the component. ![]() Setting URL, Query Parameters, Body and HeadersURL, Query parameters, Body, and Headers can be set in the blocks editor. URLSet URLSet the URL to the selected API. You can also connect a Text block or variable to set the URL. ![]() Get URLReturns the URL of the selected API. ![]() Query ParametersSet Query Parameters![]() You can add any property: value pair you want. You can add as many parameters to your API properties as you need, but each parameter has to be added one at a time. ![]() In the blocks editor, it is possible to use the ![]() In addition to creating your own objects, it is also possible to use JSON to specify the property: value pairs for your query parameters or headers. ![]() Get URLReturns the Query Parameters of the selected API. ![]() BodySet BodySet the Body of the selected API. You can connect a generate JSON from object block or a Text block. ![]() ![]() Get BodyReturns the Body of the selected API. ![]() HeadersSet HeadersSet the Headers of the selected API. You can connect a create object block. ![]() Get HeadersReturns the Header of the selected API. ![]() Get and Format (parse) Data![]() To retrieve data from an API, you simply need to use the Event Description Get ( Performs an HTTP GET request using the Url property and retrieves the Most APIs will return data in JSON format, so we'll take a few moments to walk through a few examples of how to parse this data using our Object blocks. Get Simple PropertiesExample 1: Open Weather Map APIOne of the most common output formats for APIs is JSON, short for Javascript Object Notation. The Open Weather Map API returns a JSON file like the one below. In your JSON response, objects can be found within the In the example above, Convert JSON to ObjectThe first step in parsing this response is converting the JSON response to an Object. Objects have properties (like ![]() Get Property of Object![]() Once you have converted the JSON into objects, you can then specify the ![]() Get Nested PropertiesIf we wanted to get the temperature in Dhaka from the Open Weather API above, we would need to do the following:
We can write this as getting the property ![]() You can read about getting nested values from Objects here. Get Properties from ListsYou can read about getting nested values and values from lists in Objects here. Let's work through an example. Example 2: Google Maps Distance Matrix APIYou can find a working example of this in the sample app, Ride. The JSON output of the Google Maps Distance Matrix API seems similar to the Open Weather Map API with one notable exception: it includes objects, properties and lists. Lists are items bounded by If you want to retrieve the
You can see the example below for how this would look using the Object and List blocks ![]() This can also be written as the property ![]() Upload dataUploading and deleting data is usually reserved for a private API that you or your organization owns Event Description Put ( Performs an HTTP PUT request using the Url property and retrieves the Post ( Performs an HTTP POST request using the Url property and retrieves the Patch ( Performs an HTTP PATCH request using the Url property and retrieves the Delete dataEvent Description Delete ( Performs an HTTP DELETE request using the Url property and retrieves the See AlsoYou can also post and receive messages between a web page and a Web Viewer using the Post Message function. Read more about that here. Have feedback on this doc? Please take a moment to share your feedback here: Thunkable Docs Feedback. Your valuable insights will help us improve and better serve you in the future. Last updated Was this helpful? |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |