Volume 2 - Chapter 23: Understanding REST and JSON Flashcards
What are the 6 attributes of a REST-Based (RESTful) API?
- Client/Server architecture
- Stateless operation
- Client statement of cacheable/uncacheable
- Uniform interface
- Layered
- Code-on-demand
True or False:
HTTP is required for an API to be considered RESTful.
False; while HTTP/HTTPS is common, it is not a requirement for an API to be considered RESTful.
Describe how the client/server model functions with a RESTful API.
- A REST client makes an API REST call to the REST server
- The REST server returns a response to the client
Describe how a stateless operation works with a RESTful API.
APIs that are considered RESTful are stateless; they do not track or keep information about previous API calls or request.
REST servers do not make decisions based on previous requests.
How does the function of “cacheable/uncacheable” content fit in with RESTful APIs?
- REST APIs must clearly mark content as cacheable or uncacheable
- If cacheable, a clear timer must be established for when the content needs to be downloaded again
In regards to Python and other scripting languages, describe the difference between a list and a dictionary.
A list is a list of multiple values
A dictionary is a list of matching key:value pairs
The following diagram is an example of a ____.
Dictionary, that contains multiple key:value pairs.
The following diagram is an example of a ____.
List
What are the 4 primary functions that can be performed by an application?
CRUD:
* Create: Create new variables and data structures on a server
* Read: Read existing varialbes and data structures on a server
* Update: Update existing variables and data structures on a server
* Delete: Delete existing varialbes and data structures on a server
What is the REST HTTP equivilent to a CRUD “Create” function?
POST
What is the REST HTTP equivilent to a CRUD “Read” function?
GET
What is the REST HTTP equivilent to a CRUD “Update” function?
PATCH, or PUT
What is the REST HTTP equivilent to a CRUD “Delete” function?
DELETE
What term best describes the following?
A resource that an HTTP request will act on.
A Uniform Resource Indicator (URI).
In regards to a REST GET Request, what part of a URI structure indicates the transport protocol used to transfer the requested data?
The Scheme (Protocol)
For example: https:// or http://
In regards to a REST GET Request, what part of a URI structure indicates the destination device that is hosting the requested data?
The Authority (Host:Port)
For example: 192.168.50.2:875
In regards to a REST GET Request, what part of a URI structure identifies the data, and its location on the device that is hosting it?
The Path (Resource)
For example: /root/etc/myfiles/notes.txt
In regards to a REST GET Request, what part of a URI structure identifies optional parameters for the request used for identifying variables?
The Query (Parameter)
For example: ?parm1=192.168.30.2
The following image is an example of a?
JSON output from a REST API call.
What term best describes the following?
A technique used to represent variables as text, send them over a network, or store them in a file.
Data Serialization Languages
JSON Stands for?
JavaScript Object Notation.
XML stands for?
eXtensible Markup Language.
The following image is an example of a?
XML output from a REST API call.
A technician uses a rest API to request information from a wireless controller. The technician expects to get the following key-value pairs for a dictionary called “statistics”:
* Number of Errors: 482
* Controller Uptime in Days: 399
* Device Hostname: CNTRL-WLC
How would the format of the output of this dictionary be if using XML? (Roughly)
<root> <statistics> <errornum>482</errornum> <uptime>399</uptime> <hostname>CNTRL-WLC</hostname> </statistics> </root>
The following image is an example of a?
Output from a YAML REST API call
YAML stands for?
YAML Ain’t Markup Language.
What is the main difference between YAML and XML in regards to data presentation?
YAML does not provide/define markup details, while XML does.
A technician uses a rest API to request information from a wireless controller. The technician expects to get the following key-value pairs for a dictionary called “auth”:
* Host IP: 10.10.20.20
* Username: myuser
* Password: mypass
How would the format of the output of this dictionary be if using YAML? (Roughly)
vars: auth: host: "{{ 10.10.20.20 }}" username: "{{ myuser }}" password: "{{ mypass }}"
Which data model language best matches the following?
A language that is only used for general data modeling?
YAML.
Which data model language best matches the following?
A language that is used for general data modeling and serialization?
JSON.
Which data model language best matches the following?
A language that is used for test markup and data modeling
XML
What would be the correct JSON formatting for an object that has 3 string key-value pairs?
* address1 is 123 4th St
* address2 is 456 6th St
* addresss is 789 10th St.
{ "address1": "123 4th St", "address2": "456 6th St", "address3": "789 10th St" }
Identify the problem with the following JSON dictonary:
{ "country1": "canada" "country2": "america" "country3": "sweden" }
The key:value pairs for country 1 & 2 are missing a comma. The correct formating is:
{ "country1": "canada", "country2": "america", "country3": "sweden" }
What would be the correct JSON formatting for an object that has 3 number key-value pairs?
* num1 is 295
* num2 is 3
* num3 is 1001
{ "num1": 295, "num2": 3, "num3": 101 }
What would be the correct JSON formatting for an array that has 3 string values?
* Germany
* Britain
* Canada
.
~~~
[
“Germany”,
“Britain”,
“Canada”
]
~~~
Identify the problem with the following JSON array:
{ "do it faster" "makes us stronger" "somebody" }
There are 2 problems with this output. The array should use square brackets, not curly brackets, and there is no comma between entries. The correct output would be:
[ "do it faster", "makes us stronger", "somebody" ]
What would be the correct JSON formatting for an object with 2 arrays that match the following?
favfoods: chocolate, banana, and redgrapes
favnums: 95, 1111, and 1337
.
~~~
{
“favfoods”: [
“chocolate”,
“banana”,
“redgrapes”
]
“favnums”: [
96,
1111,
1337
]
}
~~~
In JSON, the opening and closing curly brackets {} represent a(n) ____ whereas the square brackets [] represent a(n) ____
In JSON, the opening and closing curly brackets {} represent a(n) object whereas the square brackets [] represent a(n) array
What would be the correct JSON formatting for an object with 2 objects that match the following?
myscores:
* math=79
* science=93
* english=66
teachers:
* math=ashley
* science=trevor
* english=ramone
.
~~~
{
“myscores”: {
“math”: 79,
“science”: 93,
“english”: 66
}
“teachers”: {
“math”: “ashley”,
“science”: “trevor”,
“english”: “ramone”
}
}
~~~
Identify the problem with the following JSON object:
.
~~~
[
“myscores”: {
“math”: 79,
“science”: 93,
“english”: 66
}
“teachers”: {
“math”: ashley,
“science”: trevor,
“english”: ramone
}
]
~~~
There are 2 problems with the example:
- The outter brackets should be curly, as the example is an object
- The names of the teachers under the “teachers” object should have quotes
The correct output is:
{ "myscores": { "math": 79, "science": 93, "english": 66 } "teachers": { "math": "ashley", "science": "trevor", "english": "ramone" } }
True or False:
JSON does not store whitespace in its code.
True, when JSON code is stored in a file or sent over a network it does not include whitespace.