Wiki source code of Send web request to [value] and store answer in [variable]
Last modified by admin on 2023/10/05 08:53
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | (% class="box infomessage" %) | ||
2 | ((( | ||
3 | Sends a web request to a specified address (URL). Stores the answer in a specified variable. | ||
4 | |||
5 | A web request is a way to communicate with a server on the internet. This feature is used to fetch data from websites or web services, such as fetching weather information or retrieving data from a database. | ||
6 | |||
7 | **ATTENTION: Web requests are very powerful, but also very dangerous.** | ||
8 | [[Learn more ~>~>>>doc:Documentation.Web requests.WebHome]] | ||
9 | |||
10 | [[[[image:send-web-request-brick.png]]>>doc:Documentation.Web requests.WebHome]] | ||
11 | ))) | ||
12 | |||
13 | (% class="row" %) | ||
14 | ((( | ||
15 | (% class="col-xs-12 col-sm-6" %) | ||
16 | ((( | ||
17 | (% class="box" %) | ||
18 | ((( | ||
19 | ==== **Example** ==== | ||
20 | |||
21 | Sends a web request to retrieve a random joke. The answer is extracted with the help of regular expressions. | ||
22 | |||
23 | [[image:send-web-request-example.png||alt="store-column-example.png"]] | ||
24 | |||
25 | The free joke api returns data in the following json format: | ||
26 | |||
27 | **{"id":10,"type":"general","setup":"What kind of shoes does a thief | ||
28 | wear?","punchline":"Sneakers"}** | ||
29 | |||
30 | |||
31 | To extract the setup phrase in case you stored the result in variable "joke", use the following regular expression: | ||
32 | **regular expression( '"setup":"(.*?)"' , "joke" )** | ||
33 | |||
34 | |||
35 | The result will be: What kind of shoes does a thief wear? | ||
36 | |||
37 | |||
38 | To extract the setup phrase, use the following regular expression: | ||
39 | **regular expression( '"punchline":"(.*?)"' , "joke" )** | ||
40 | |||
41 | The result will be: Sneakers | ||
42 | ))) | ||
43 | ))) | ||
44 | |||
45 | (% class="col-xs-12 col-sm-6" %) | ||
46 | ((( | ||
47 | (% class="box" %) | ||
48 | ((( | ||
49 | ==== **Result** ==== | ||
50 | |||
51 | [[[[image:null4.png||alt="Download"]]>>https://share.catrob.at/app/project/045e7be6-db1a-11ea-a5c3-005056a36f47]] | ||
52 | |||
53 | [[image:send-web-request-example.gif||alt="store-column-example.gif"]] | ||
54 | ))) | ||
55 | ))) | ||
56 | ))) |