Chapter 47 - Understanding REST and JSON Flashcards
1
Q
What is a library?
A
- Prebuilt index of data that can be used instead of writing the equivalent from scratch
2
Q
What are the attributes that define REST APIs?
A
- Client/server architecture - Uses API calls (E.g. HTTP requests) to access data on the REST server
- Stateless operation - Does not use information from previous API exchanges to influence future API exchanges
- Clear statement of cacheable and uncacheable - Marks data that should or should not be cached for better performance (if cached, the server does not have to retrieve a resource for the client after already retrieving it within a certain timeframe)
- Uniform interface
- Layered
- Code-on-demand
3
Q
What are Simple Variables?
A
- Variables with a single data name and a single attributed value
4
Q
What are Array Data Structures?
A
- Data Structure with a single data key but multiple attributed values
5
Q
What are Object Data Structures?
A
- Data structures that contain multiple key:value pairs
- Sometimes called a Dictionary
6
Q
Why do a lot of REST APIs use HTTP as their networking protocol?
A
- Very similar (e.g. both client/server, both stateless, both clearly mark cacheable and uncacheable data)
- REST APIs can also use URIs to specify in HTTP what data it needs to perform an action on
7
Q
What is CRUD?
A
- An acronym for the four primary actions of an application:
- Create - Allows users to create variables and data structures at a server and set their initial values
- Read - Allows users to retrieve the current value of variables that exist at a server
- Update - Allows the client to update variables and data structures at a server
- Delete - Allows the client to delete variables from a server
8
Q
List HTTP verbs and their corresponding CRUD terms
A
- POST - Create
- GET - Read
- PATCH/PUT - Update
- DELETE - Delete
9
Q
What are the different parts of a URI?
A
HTTPS://google.com/path/to/resource?specific=query
- Before the :// - Protocol (Scheme)
- Immediately after the :// - The hostname of the server (authority)
- Immediately after the / - The path to the resource on the server
- Immediately after the ? - A query that specifies the variable that the client is querying at a given destination
10
Q
What is JSON?
A
- JavaScript Object Notation
- Open standard file format and data interchange format that stores and transmits data in human readable text
- Data serialisation language
- Commonly used in REST APIs
- Whitespace is insignificant
11
Q
What is a Data Serialisation Language?
A
- Provides a standardised method of representing data between programs. Useful when programs are written in different languages as they may interpret/represent variables differently
- An example is JSON, XML, YAML
- Sometimes known as a Data Modelling Language
12
Q
What is XML?
A
- eXtensible Markup Language
- Data serialisation language
- A successor to HTML that improves on the ability for variables to be changed dynamically
- Commonly used in REST APIs and web pages
- Whitespace does not change the meaning of data
- key value pairs are written as <key> value </key>
13
Q
What is YAML?
A
- YAML Ain’t Markup Language
- Data serialisation language
- Unlike XML focuses more on data model details than markup
- Commonly used in Ansible
- White space does change the meaning of data
- Files start with ‘—’
- Lists start with ‘-‘
- Key value pairs are defined as key:value
14
Q
What is markup in the context of programming?
A
- The ability for a programming language to add more information to variables to define how they are displayed
15
Q
JSON syntax rules
A
- Key:Value Pair - Every colon identifies one key:value pair with the key before the colon and the value after.
- Key - Text inside double quotes, before a colon that is used as a name that references a value
- Value - Item after the colon that represents the value of the key. These can be:
- string
- number
- null
- boolean
- Array
- Object - An unordered list of key:value pairs - Multiple Pairs - Separate each pair with a comma at the end of each pair apart from the last one
- Curly brackets - Begin and end a JSON object. A series of key:value pairs enclosed in curly brakcets. Python knows them as dictionaries.
- Square brackets - Begin and end a JSON array. A series of values (not key:value pairs) enclosed in square brackets. Python knows them as lists.
- Objects and arrays can be nested within each other
- Whitespace does not change the meaning of data