2023:Web Service Lookup (Lookup Specification): Difference between revisions
| Line 119: | Line 119: | ||
<tabs style="margin:20px"> | <tabs style="margin:20px"> | ||
<tab name = "GET Request" style="margin:20px"> | <tab name = "GET Request" style="margin:20px"> | ||
A GET requests, as their name states, get data from | A GET requests, as their name states, get data from an API, then pass it into Grooper; usually in a JSON format. Once the data has been received from the source, it is given back to Grooper in a neat little bundle—which can be made neater still with '''''Record''''' and '''''Value Selectors''''', which are detailed below. | ||
{|cellpadding="12" cellspacing="4" style="margin:12px" | {|cellpadding="12" cellspacing="4" style="margin:12px" | ||
|valign=top style="width:40%"| | |valign=top style="width:40%"| | ||
For GET requests, we'll take a look at the GET Example '''Content Model'''. | For GET requests, we'll take a look at the GET Example '''Content Model'''. | ||
# To access the GET request, select the Data Model, then click the ellipses to the right of | # To access the GET request, select the '''Data Model''', then click the ellipses to the right of '''''Lookup''''' under '''''Behavior'''''. | ||
|valign=top| | |valign=top| | ||
[[File:2023-Web Service Lookup-GETvsPOST Requests-GET Requsts-01.png]] | [[File:2023-Web Service Lookup-GETvsPOST Requests-GET Requsts-01.png]] | ||
|- | |- | ||
|valign=top| | |valign=top| | ||
# Here, you will choose which type of request referred to as a | # Here, you will choose which type of request (referred to as a '''''Verb''''') you wish to use. As you can see, we have chosen GET. | ||
#* Verbs are vital. Much like how you cannot have a sentence without a verb, you cannot have a Web Service Lookup without a request/Verb. | #* '''''Verbs''''' are vital. Much like how you cannot have a sentence without a verb, you cannot have a '''''Web Service Lookup''''' without a request/'''''Verb'''''. | ||
#* While HTTP requests are varied, Grooper only concerns itself with GET and POST | #* While HTTP requests are varied, Grooper only concerns itself with GET and POST | ||
# Now, we'll move ono Record and Value Selectors. | # Now, we'll move ono '''''Record''''' and '''''Value Selectors'''''. | ||
#* Record | #* '''''Record Selectors''''' are optional, as leaving the section blank will give you the option to simply select the type of record at the root of either the JSON or XML document. However, for this particular case, since we're going to be displaying a place's location based on its ZIP Code, we will need a '''''Record Selector''''' to pass the pieces of information we want into the appropriate fields in Grooper. This is because we have multiple pieces of data that we need to feed into our '''Data Model'''. Thus, the '''''Record Selector''''', "Places" acts as an array through which the information associated with whatever zip code our URL retrieves will pass. | ||
#* Said passing is then refined by the Value Selectors we have set up. These act as signs along the path which our retrieved information will travel, pointing out the field in which the specific piece of information needs to be placed. | #* Said passing is then refined by the '''''Value Selectors''''' we have set up. These act as signs along the path which our retrieved information will travel, pointing out the field in which the specific piece of information needs to be placed. | ||
|valign=top| | |valign=top| | ||
[[File:2023-Web Service Lookup-GETvsPOST Requests-GET Requsts-02.png]] | [[File:2023-Web Service Lookup-GETvsPOST Requests-GET Requsts-02.png]] | ||
|- | |- | ||
|valign=top| | |valign=top| | ||
* As evidenced, we have two Value Selectors, "state" and "[place name]"; "state" receives the name of the state associated with the zip code pulled by the API and "[place name]" is the city name relative to that zip code. Once this information is obtained by the API, it is then passed back to Grooper and filtered first through the array that is our record selector, then additionally through our value selectors. This is done by setting the "Path", i.e. a scalar value from the record as well as a Target Field—the Data Field where the information will be displayed. For example, when entered into the URL, the zip code 57701 will return the following: | * As evidenced, we have two '''''Value Selectors''''', "state" and "[place name]"; "state" receives the name of the state associated with the zip code pulled by the API and "[place name]" is the city name relative to that zip code. Once this information is obtained by the API, it is then passed back to Grooper and filtered first through the array that is our '''''record selector''''', then additionally through our '''''value selectors'''''. This is done by setting the "Path", i.e. a scalar value from the record as well as a Target Field—the Data Field where the information will be displayed. For example, when entered into the URL, the zip code 57701 will return the following: | ||
**<code>{"post code": "57701", "country": "United States", "country abbreviation": "US", "places": [{"place name": "Rapid City", "longitude": "-103.2052", "state": "South Dakota", "state abbreviation": "SD", "latitude": "44.1415"}]}</code> | **<code>{"post code": "57701", "country": "United States", "country abbreviation": "US", "places": [{"place name": "Rapid City", "longitude": "-103.2052", "state": "South Dakota", "state abbreviation": "SD", "latitude": "44.1415"}]}</code> | ||
*As you can see, the place name, and state are the paths where we pick up the desired information. Once they're sent back to our Data Model, "place name" is deposited into the Target Field of City, and "state" into State respectively. | *As you can see, the place name, and state are the paths where we pick up the desired information. Once they're sent back to our '''Data Model''', "place name" is deposited into the Target Field of City, and "state" into State respectively. | ||
|valign=top| | |valign=top| | ||
[[File:2023-Web Service Lookup-GETvsPOST Requests-GET Requsts-03.png]] | [[File:2023-Web Service Lookup-GETvsPOST Requests-GET Requsts-03.png]] | ||
| Line 150: | Line 150: | ||
{|cellpadding="12" cellspacing="4" style="margin:12px" | {|cellpadding="12" cellspacing="4" style="margin:12px" | ||
|valign=top style="width:40%"| | |valign=top style="width:40%"| | ||
* To view the POST request, select the Data Model under the POST Examples Content Model, and click the | * To view the POST request, select the '''Data Model''' under the POST Examples Content Model, and click the ellipses to the right of the '''''Lookup''''' property, under '''''Behavior'''''. | ||
|valign=top| | |valign=top| | ||
[[File:2023-Web Service Lookup-GETvsPOST Requests-POST Requsts-01.png]] | [[File:2023-Web Service Lookup-GETvsPOST Requests-POST Requsts-01.png]] | ||
| Line 161: | Line 161: | ||
|valign=top| | |valign=top| | ||
* First, we tell Grooper which path we're using, JSON or XML. As you can see, we've chosen XML for this request. | * First, we tell Grooper which path we're using, JSON or XML. As you can see, we've chosen XML for this request. | ||
* Just like our GET example, we want to look up zip codes, and pass that information, along with the city and state related to said zip code, into our Data Model. | * Just like our GET example, we want to look up zip codes, and pass that information, along with the city and state related to said zip code, into our '''Data Model'''. | ||
** For POST requests, the API expects to know where the request is coming from, thus you will need to input your computer's/business' user id. | ** For POST requests, the API expects to know where the request is coming from, thus you will need to input your computer's/business' user id. | ||
* Thus, we outline where we wish to go: CityStateLookup -> ZipCode and then end our html statements accordingly. | * Thus, we outline where we wish to go: CityStateLookup -> ZipCode and then end our html statements accordingly. | ||
| Line 169: | Line 169: | ||
|- | |- | ||
|valign=top| | |valign=top| | ||
* As before, we have set up our Record and Value Selectors. Since we're using a POST request, instead of an array through which information will be fed and sorted, we enter what looks to be the latter portion of a URL path. Specifically, we're telling the API and Grooper that once we reach CityStateLookup, we're utilizing the zip code to obtain it and its related information. | * As before, we have set up our '''''Record''''' and '''''Value Selectors'''''. Since we're using a POST request, instead of an array through which information will be fed and sorted, we enter what looks to be the latter portion of a URL path. Specifically, we're telling the API and Grooper that once we reach CityStateLookup, we're utilizing the zip code to obtain it and its related information. | ||
|valign=top| | |valign=top| | ||
[[File:2023-Web Service Lookup-GETvsPOST Requests-POST Requsts-05.png]] | [[File:2023-Web Service Lookup-GETvsPOST Requests-POST Requsts-05.png]] | ||
|- | |- | ||
|valign=top| | |valign=top| | ||
* Similar to the GET request, once we have the zip code data and its related information in Grooper, we feed it through the value selectors and sort each piece of information accordingly. City and State in this case display the city and state names respectively. | * Similar to the GET request, once we have the zip code data and its related information in Grooper, we feed it through the '''''value selectors''''' and sort each piece of information accordingly. City and State in this case display the city and state names respectively. | ||
|valign=top| | |valign=top| | ||
[[File:2023-Web Service Lookup-GETvsPOST Requests-POST Requsts-06.png]] | [[File:2023-Web Service Lookup-GETvsPOST Requests-POST Requsts-06.png]] | ||
Revision as of 12:32, 30 March 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.
Overview
Below is a brief guide on how to access a Web Service Lookup in Grooper, as well as a quick glance at its components.
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.
|
|
|
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:
|
The latter half of the Web Service Lookup; this is where the information is passed into Grooper. It is divided into the following:
|
Now that we understand where in Grooper to access the Web Service Lookup as well as its composite parts, we're ready to dive further in and explore how the Request and Response section work though the use of Verb and Message Format.
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.
- Also, it is important to be aware that 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.
- In the case of our Web Service Lookup, we send the API some data from Data Fields in our Data Model and receive additional data from the API endpoint.
- 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.
- Thus, the message received in this example is XML formatted.
- This example will use an XPath expression in the Record Selector property to return the values we want in the XML.
- 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.
A GET requests, as their name states, get data from an API, then pass it into Grooper; usually in a JSON format. Once the data has been received from the source, it is given back to Grooper in a neat little bundle—which can be made neater still with Record and Value Selectors, which are detailed below.
|
For GET requests, we'll take a look at the GET Example Content Model.
|
|
|
|
|
Unlike GET requests, 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 can depend 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 is 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 using data exchange. 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












