2023:Web Service Lookup (Lookup Specification): Difference between revisions
| Line 132: | Line 132: | ||
==== GET Request ==== | ==== GET Request ==== | ||
<tabs style="margin:20px"> | |||
<tab name="Add Lookup" style="margin:20px"> | |||
{|cellpadding=10 cellspacing=5 | {|cellpadding=10 cellspacing=5 | ||
GET requests fetch information from an API, and merge data from the API into a Grooper '''Data Field''' through @variables. | GET requests fetch information from an API, and merge data from the API into a Grooper '''Data Field''' through @variables. | ||
| Line 145: | Line 147: | ||
|valign=top| | |valign=top| | ||
[[File:2023-Web-Service-Lookup-How To-Adding-a-Web-Service-Lookup-02.png]] | [[File:2023-Web-Service-Lookup-How To-Adding-a-Web-Service-Lookup-02.png]] | ||
| | |} | ||
|valign=top| | </tab> | ||
<tab name ="Request" style="margin:20px"> | |||
{|cellpadding=10 cellspacing=5 | |||
|valign=top style="width:40%"| | |||
#<li value=5> Notice that GET is automatically selected. | #<li value=5> Notice that GET is automatically selected. | ||
# First, set up the URL. | # First, set up the URL. | ||
| Line 153: | Line 158: | ||
|- | |- | ||
|valign=top| | |valign=top| | ||
#<li value=7> Enter the URL that will start the call to your API. Since we're wanting to retrieve city state information related to zip codes, we'll be using Zippopotamus. [https://www.zippopotam.us/] | #<li value=7> Enter the URL that will start the call to your API. | ||
#*Since we're wanting to retrieve city state information related to zip codes, we'll be using Zippopotamus. [https://www.zippopotam.us/] | |||
# When finished, click OK. | # When finished, click OK. | ||
|valign=top| | |valign=top| | ||
[[File:2023-Web-Service-Lookup-How To-Configuring-a-Web-Service-Lookup-GET-Request-02.png]] | [[File:2023-Web-Service-Lookup-How To-Configuring-a-Web-Service-Lookup-GET-Request-02.png]] | ||
| | |} | ||
|valign=top| | </tab> | ||
#<li value=9> Now, for the Record Selector. Since we're passing multiple pieces of information back to Grooper (city and state name relevant to our zip code), the JSON format of our GET request parses said information into an array called "places." See here for visual representation: [https://api.zippopotam.us/us/57701 ZIP] | <tab name ="Response" style="margin:20px"> | ||
{|cellpadding=10 cellspacing=5 | |||
|valign=top style="width:40%"| | |||
#<li value=9> Now, for the Record Selector. | |||
#*Since we're passing multiple pieces of information back to Grooper (city and state name relevant to our zip code), the JSON format of our GET request parses said information into an array called "places." See here for visual representation: [https://api.zippopotam.us/us/57701 ZIP] | |||
#* Hence, we'll call our Record Selector "places." | #* Hence, we'll call our Record Selector "places." | ||
|valign=top| | |valign=top| | ||
| Line 177: | Line 187: | ||
|- | |- | ||
|valign=top| | |valign=top| | ||
#<li value=13> Select the Target Field that you would like the data to be mapped to. Notice that these fields are the same as the '''Data Fields''' in our '''Data Model'''. The Target Field is the final destination for the data retrieved through the GET request, and where it will be displayed. | #<li value=13> Select the Target Field that you would like the data to be mapped to. | ||
#*Notice that these fields are the same as the '''Data Fields''' in our '''Data Model'''. The Target Field is the final destination for the data retrieved through the GET request, and where it will be displayed. | |||
|valign=top| | |valign=top| | ||
[[File:2023-Web-Service-Lookup-How Ro-a-Web-Service-Lookup-GET-Request-05.png]] | [[File:2023-Web-Service-Lookup-How Ro-a-Web-Service-Lookup-GET-Request-05.png]] | ||
|} | |} | ||
</tab> | |||
</tabs> | |||
==== POST Request ==== | ==== POST Request ==== | ||
Revision as of 12:50, 7 April 2023
| WIP |
This article is a work-in-progress or created as a placeholder for testing purposes. This article is subject to change and/or expansion. It may be incomplete, inaccurate, or stop abruptly. This tag will be removed upon draft completion. |
Web Service Lookup is a type of Lookup that can be performed in Grooper. It looks up external data at an API (Application Programing Interface) endpoint by calling a web service.
About
Web Service Lookup is a new data lookup method in Grooper 2023. It allows Grooper to collect and validate data by calling a web service. The Web Service Lookup issues an HTTP GET or POST request and parses one or more records from the response. For example, you could use the Web Service Lookup to validate mailing addresses using the USPS Web Tools API. The Web Service Lookup would pass Data Field values Grooper collects in the request parameters and receive various values from the API from the web call. If you passed a Grooper extracted zip code in the web request, you could return the city and state from the API.
- For GET requests, parameters may be passed in the URL using "@variables" to replace a portion of the URL with a Data Field's value.
- For POST requests, parameters may be passed using "@variables" in the request body.
The Web Service Lookup supports both JSON and XML message formats.
How To
Below is a brief guide on how to access a Web Service Lookup in Grooper, as well as a quick glance at its components.
Adding a Web Service Lookup
Getting Started
For this overview, we'll be going over how to access the Web Service Lookup. This particular lookup will will be accessing an API through GET/POST requests and to retrieve (or submit) a zip code and its related information (city and state). Further details will be expanded upon later in this article.
|
|
|
Request
The "Request" is the first half of the Web Service Lookup. Essentially, it's what does the fetching of the information we want to pass into Grooper, and is broken down into the following pieces:
|
Response
The latter half of the Web Service Lookup; this is where the information is passed into Grooper. It is divided into the following:
|
Configuring a Web Service Lookup
With an understanding of the components, we can now set a request. Below, we'll explain how to set up both GET and POST requests.
GET vs POST Requests
In the two examples below, we will use a Web Service Lookup to lookup a city and state for a given zip code. One will use a GET verb for the web request, the other will use the POST verb. For more information on GET and POST requests, please click the following link: W3Schools
| ⚠ |
The following two examples are to give very generic guidance on using the GET and POST requests. Be aware:
|
The first example issues a GET request to an API. GET requests retrieve data from an API.
- For GET requests, the entire web call is made using the URL. The call itself is altered by simply changing part of the URL. Data Field values are merged with the URL by using @variables.
- Furthermore, the message received in this example is JSON formatted.
- This example will use the Record Selector property to return values of an array in the JSON message.
- However, be aware the message format depends on each individual API. Be sure to read the API's documentation to know if the API supports XML or JSON requests.
- Be aware! GET requests are less secure than POST requests. GET requests should NEVER be used when dealing with sensitive data.
The second example issues a POST request to an API. POST requests send data to an API.
- Be aware! Even though we're sending data. Our goal in doing so is to get some other data back from the API.
- So, as far as the Web Service Lookup goes, both the GET and POST requests do similar things. We send the API some data from Data Fields in our Data Model and receive additional data from the API endpoint.
- The only difference is how that data is sent. For POST requests, the data is sent in the "request body".
- For POST requests, the URL starts the call the web service, but additional information in the request body is required to complete the request and return a response. We will need to use the Request Body property to define Data Field values used in the request.
- This example will use an XPath expression in the Record Selector property to return the values we want in the XML.
- Be aware! the message format depends on each individual API. Be sure to read the API's documentation to know if the API supports XML or JSON requests.
GET Request
|
|
|
|
|
|
|
|
|
|
|
|
|
POST Request
POST requests send, or post, data to a requested server. The data is included in the URL path and uploaded for storage, making a change on that server. POST requests are not cached and do not remain in browser history, making them ideal for more sensitive data as opposed to GET requests.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSON vs XML
Grooper offers the option to choose between JSON or XML formatting when creating your lookup. The chosen Message Format depends on your preferences as well as the type of data you're working with. The differences between the two are highlighted briefly below. For more information on JSON and XML, please click the following link: AppMaster
JSON
JSON (Java Script Object Notation) is used for interchanging data. It is language independent and is ideal for sharing information to APIs due to its way of serializing complex information into a string. It is quicker and easier to write due to its lack of need for end tags and use of arrays, and can be parsed into a Java Script object. For more information on how JSON differs from XML, click here: W3Schools
XML
XML (Extensible Markup Language) is standard for storing and exchanging data. In XML, data is a collection of elements and attributes which can be nested within one another and are contained within opening and closing tags, instead of arrays. Said tags are used to define specific pieces of data for ease of coding. XML is designed to carry data. It is more secure than JSON and supports comments. For more information on how XML differs from JSON and the benefits it may provide, click here: GeeksforGeeks




















