C 32/CSE 42, UC Irvine Problem 9 Suppose you are working on a program that requi
ID: 3904241 • Letter: C
Question
C 32/CSE 42, UC Irvine Problem 9 Suppose you are working on a program that requires an API call to some website called http://www.booisawesome.com. We wish to access the customers API webpage of the website-the API takes the parameters: date 12-5-16 search dog Write the encoded URL that we would use in order to send a HTTPS request to the web API for the BoolsAwesome website in the box below. programming a function to generate the encoded URL as you wrote in part (a), why do we use n urlib.parse.urlencode instead of just concatenating a string for the URL ourselves? the functio (c) After getting the result of the HTTPS request from part (a), we parse the JSON response. Why do we use the json library to parse the JSON response? In other words, how did the library make it easier for a program to process the information in the JSON response? (d) What is the purpose of using protocols in writing programs?Explanation / Answer
Here an URL (Uniform resource locator) is a set of strings to define a location in the World Wide Web (www). It can also be used to pass information to the destination. Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&".
Hence to answer part a) of the question www.mybooisawesosme.com?date=12-5-16&search=dog
For answer part b) a URLs can only be sent over the Internet using the ASCII character-set. Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format. URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.Hence we use the function instead of string concatenation.
For answer part c) JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging.It is based on a subset of JavaScript language (the way objects are built in JavaScript). As stated in the MDN, some JavaScript is not JSON, and some JSON is not JavaScript.
JSON is built on two structures:
These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages also be based on these structures. Hence we use JSON to easily convert one format like arrays, objects in php etc to JSON format and vice versa.
Answer d) Sometimes referred to as an access method, a protocolis a standard used to define a method of exchanging data over a computer network, such as local area network, Internet, Intranet, etc. Each protocol has its own method of how data is formatted when sent and what to do with it once received, how that data is compressed, or how to check for errors in the data.One of the most common and known protocols is HTTP(HyperText Transfer Protocol), which is a protocol used to transmit data over the world wide web (Internet).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.