Podcast
Questions and Answers
Which of these is NOT considered a REST Resource?
Which of these is NOT considered a REST Resource?
What is the primary purpose of a Uniform Resource Identifier (URI) in REST?
What is the primary purpose of a Uniform Resource Identifier (URI) in REST?
How does a client specify the desired representation of a resource using a URI?
How does a client specify the desired representation of a resource using a URI?
What does a server respond with after receiving a client request for a specific resource representation?
What does a server respond with after receiving a client request for a specific resource representation?
Signup and view all the answers
What is the purpose of the 'scheme' component in a URI?
What is the purpose of the 'scheme' component in a URI?
Signup and view all the answers
What does REST stand for ?
What does REST stand for ?
Signup and view all the answers
Which of the following is NOT a characteristic of REST resources?
Which of the following is NOT a characteristic of REST resources?
Signup and view all the answers
What is the primary purpose of using a query string in a URI?
What is the primary purpose of using a query string in a URI?
Signup and view all the answers
What is the purpose of the '?query' parameter in a URL?
What is the purpose of the '?query' parameter in a URL?
Signup and view all the answers
What determines the format of a resource representation?
What determines the format of a resource representation?
Signup and view all the answers
How does a browser know how to interpret a resource representation?
How does a browser know how to interpret a resource representation?
Signup and view all the answers
What does the 'action' refer to in the context of a resource representation?
What does the 'action' refer to in the context of a resource representation?
Signup and view all the answers
How can a client access different representations of the same resource?
How can a client access different representations of the same resource?
Signup and view all the answers
What type of data can be returned from a GraphQL server?
What type of data can be returned from a GraphQL server?
Signup and view all the answers
Which of these statements describes GraphQL's approach to data structure?
Which of these statements describes GraphQL's approach to data structure?
Signup and view all the answers
What is the difference between a GET request and a PUT request in a RESTful system?
What is the difference between a GET request and a PUT request in a RESTful system?
Signup and view all the answers
What is the purpose of a GraphQL Mutation?
What is the purpose of a GraphQL Mutation?
Signup and view all the answers
Which method is used to delete a resource in a RESTful system?
Which method is used to delete a resource in a RESTful system?
Signup and view all the answers
What is the main difference between GraphQL's discoverability and REST's discoverability?
What is the main difference between GraphQL's discoverability and REST's discoverability?
Signup and view all the answers
What is the main performance benefit of GraphQL over REST?
What is the main performance benefit of GraphQL over REST?
Signup and view all the answers
What is the purpose of HTTP status codes in a RESTful service?
What is the purpose of HTTP status codes in a RESTful service?
Signup and view all the answers
How would you describe the relationship between a GraphQL schema and stored data?
How would you describe the relationship between a GraphQL schema and stored data?
Signup and view all the answers
What are the four main actions that can interact with resources in a RESTful system?
What are the four main actions that can interact with resources in a RESTful system?
Signup and view all the answers
What is the primary purpose of GraphQL's query language?
What is the primary purpose of GraphQL's query language?
Signup and view all the answers
What is the purpose of Custom Token Authentication in securing RESTful services?
What is the purpose of Custom Token Authentication in securing RESTful services?
Signup and view all the answers
What is the main advantage of using GraphQL over a RESTful API?
What is the main advantage of using GraphQL over a RESTful API?
Signup and view all the answers
In a RESTful system, what is generally true about the URI of a resource when it is created using the POST method?
In a RESTful system, what is generally true about the URI of a resource when it is created using the POST method?
Signup and view all the answers
Which statement best describes Oauth as a method for securing RESTful services?
Which statement best describes Oauth as a method for securing RESTful services?
Signup and view all the answers
Which of the following is NOT a standard action under HTTP?
Which of the following is NOT a standard action under HTTP?
Signup and view all the answers
Which HTTP status code category indicates a client-side error?
Which HTTP status code category indicates a client-side error?
Signup and view all the answers
What does the term "CRUD" refer to in the context of RESTful systems?
What does the term "CRUD" refer to in the context of RESTful systems?
Signup and view all the answers
What is a key advantage of RESTful systems over other web applications?
What is a key advantage of RESTful systems over other web applications?
Signup and view all the answers
What does the URI "https://api.github.com/users/octocat" represent in the example of the Github API?
What does the URI "https://api.github.com/users/octocat" represent in the example of the Github API?
Signup and view all the answers
What is the purpose of the access_token parameter in the Instagram API URI "http://api.instagram.com/v1/locations/search?access_token=ACCESS_TOKEN&lat=40.7127&lng=74.0059"?
What is the purpose of the access_token parameter in the Instagram API URI "http://api.instagram.com/v1/locations/search?access_token=ACCESS_TOKEN&lat=40.7127&lng=74.0059"?
Signup and view all the answers
Which statement is TRUE about the PUT method in a RESTful system?
Which statement is TRUE about the PUT method in a RESTful system?
Signup and view all the answers
What is a key disadvantage of HTTP Basic Authentication in RESTful services?
What is a key disadvantage of HTTP Basic Authentication in RESTful services?
Signup and view all the answers
Which of the following statements is NOT TRUE about using a GET request in a RESTful system?
Which of the following statements is NOT TRUE about using a GET request in a RESTful system?
Signup and view all the answers
Which of the following is NOT a property of a REST system?
Which of the following is NOT a property of a REST system?
Signup and view all the answers
What is the primary purpose of a REST system, as described in the text?
What is the primary purpose of a REST system, as described in the text?
Signup and view all the answers
What is the significance of the statement 'REST is not a technology or framework'?
What is the significance of the statement 'REST is not a technology or framework'?
Signup and view all the answers
How does a web server demonstrate the principles of REST?
How does a web server demonstrate the principles of REST?
Signup and view all the answers
What is the difference between REST and SOAP?
What is the difference between REST and SOAP?
Signup and view all the answers
What is the primary disadvantage of HTTP Basic Authentication when used without HTTPS?
What is the primary disadvantage of HTTP Basic Authentication when used without HTTPS?
Signup and view all the answers
What is the primary purpose of OAuth 2.0 for RESTful services?
What is the primary purpose of OAuth 2.0 for RESTful services?
Signup and view all the answers
What is the main difference between HTTP Basic Authentication and OAuth 2.0 in terms of user information sharing?
What is the main difference between HTTP Basic Authentication and OAuth 2.0 in terms of user information sharing?
Signup and view all the answers
Which scenario exemplifies a suitable use case for OAuth 2.0?
Which scenario exemplifies a suitable use case for OAuth 2.0?
Signup and view all the answers
What is the primary role of the authorization token in OAuth 2.0?
What is the primary role of the authorization token in OAuth 2.0?
Signup and view all the answers
What is the output of the convertCtoF()
method in the Java REST example provided?
What is the output of the convertCtoF()
method in the Java REST example provided?
Signup and view all the answers
What is the purpose of the @Path
annotation in the Java REST example code?
What is the purpose of the @Path
annotation in the Java REST example code?
Signup and view all the answers
What is the difference between the convertCtoF()
and convertCtoFfromInput()
methods in the REST example?
What is the difference between the convertCtoF()
and convertCtoFfromInput()
methods in the REST example?
Signup and view all the answers
What is the purpose of the @Produces
annotation in the Java REST example?
What is the purpose of the @Produces
annotation in the Java REST example?
Signup and view all the answers
What is the main difference between the convertCtoF()
and convertFtoC()
methods in the REST example?
What is the main difference between the convertCtoF()
and convertFtoC()
methods in the REST example?
Signup and view all the answers
What is the key difference between REST and GraphQL in terms of data retrieval?
What is the key difference between REST and GraphQL in terms of data retrieval?
Signup and view all the answers
What is the main reason for using the JSONObject
class in the convertFtoC()
method in the REST example?
What is the main reason for using the JSONObject
class in the convertFtoC()
method in the REST example?
Signup and view all the answers
In the Java REST example code, what is the role of Response.status(200).entity(result).build()
?
In the Java REST example code, what is the role of Response.status(200).entity(result).build()
?
Signup and view all the answers
What does @PathParam("c") Double c
in the convertCtoFfromInput()
method represent?
What does @PathParam("c") Double c
in the convertCtoFfromInput()
method represent?
Signup and view all the answers
Flashcards
REST
REST
Representational State Transfer; an architectural style for designing networked applications.
Client-Server Architecture
Client-Server Architecture
A structure where client requests resources from a server, which then responds to those requests.
Stateless System
Stateless System
A property where each request is independent; no client session data stored on the server.
Caching System
Caching System
Signup and view all the flashcards
Uniformly Accessible
Uniformly Accessible
Signup and view all the flashcards
Static vs Dynamic Pages
Static vs Dynamic Pages
Signup and view all the flashcards
REST Abstractions
REST Abstractions
Signup and view all the flashcards
Definition of Resource
Definition of Resource
Signup and view all the flashcards
Unique Address of Resource
Unique Address of Resource
Signup and view all the flashcards
URI Stability
URI Stability
Signup and view all the flashcards
Negotiating Resource Representation
Negotiating Resource Representation
Signup and view all the flashcards
Structure of URI
Structure of URI
Signup and view all the flashcards
URI Example
URI Example
Signup and view all the flashcards
Resource Representations
Resource Representations
Signup and view all the flashcards
Content-Type
Content-Type
Signup and view all the flashcards
HTTP Communication
HTTP Communication
Signup and view all the flashcards
URI
URI
Signup and view all the flashcards
Representation Formats
Representation Formats
Signup and view all the flashcards
GraphQL
GraphQL
Signup and view all the flashcards
GraphQL Schema
GraphQL Schema
Signup and view all the flashcards
GraphQL Types
GraphQL Types
Signup and view all the flashcards
GraphQL Query
GraphQL Query
Signup and view all the flashcards
GraphQL Mutation
GraphQL Mutation
Signup and view all the flashcards
GraphQL JSON Output
GraphQL JSON Output
Signup and view all the flashcards
Over-fetching in GraphQL
Over-fetching in GraphQL
Signup and view all the flashcards
GraphQL vs REST
GraphQL vs REST
Signup and view all the flashcards
720p video
720p video
Signup and view all the flashcards
HTTP Actions
HTTP Actions
Signup and view all the flashcards
CRUD Actions
CRUD Actions
Signup and view all the flashcards
GET Method
GET Method
Signup and view all the flashcards
POST Method
POST Method
Signup and view all the flashcards
PUT Method
PUT Method
Signup and view all the flashcards
DELETE Method
DELETE Method
Signup and view all the flashcards
Muh HTTP Status Codes
Muh HTTP Status Codes
Signup and view all the flashcards
API Resources
API Resources
Signup and view all the flashcards
Custom Token Authentication
Custom Token Authentication
Signup and view all the flashcards
HTTP Basic Authentication
HTTP Basic Authentication
Signup and view all the flashcards
OAuth
OAuth
Signup and view all the flashcards
JSON Representation
JSON Representation
Signup and view all the flashcards
Resource URI
Resource URI
Signup and view all the flashcards
Data Action Mapping
Data Action Mapping
Signup and view all the flashcards
HTTP Error Code 401
HTTP Error Code 401
Signup and view all the flashcards
Advantages of HTTP Basic Auth
Advantages of HTTP Basic Auth
Signup and view all the flashcards
Disadvantages of HTTP Basic Auth
Disadvantages of HTTP Basic Auth
Signup and view all the flashcards
OAuth 2.0
OAuth 2.0
Signup and view all the flashcards
Third Party Access in OAuth 2.0
Third Party Access in OAuth 2.0
Signup and view all the flashcards
Authorization Token
Authorization Token
Signup and view all the flashcards
OAuth 2.0 Process
OAuth 2.0 Process
Signup and view all the flashcards
User Experience in OAuth 2.0
User Experience in OAuth 2.0
Signup and view all the flashcards
Examples of OAuth in Games
Examples of OAuth in Games
Signup and view all the flashcards
Java REST Example Structure
Java REST Example Structure
Signup and view all the flashcards
convertCtoF Method
convertCtoF Method
Signup and view all the flashcards
convertFtoC Method
convertFtoC Method
Signup and view all the flashcards
Secure HTTP Methods
Secure HTTP Methods
Signup and view all the flashcards
Study Notes
REST Introduction
- REST stands for REpresentational State Transfer
- Proposed by Roy Fielding in his PhD thesis in 2000
- Considered an Architectural Style, not a technology or framework
- Defined by principles and constraints; in contrast to SOAP, which is more constrained
REST Properties
- Implements client-server architecture
- Stateless system: each request treated independently, no session storage
- Supports caching mechanism
- Uniformly accessible: each resource has a unique address and access point
REST Architecture
- Web server acts as a REST system when a browser enters a URL
- Browser receives a representation of the resource's current state (can be static or dynamic -like news sites, blogs)
- Example: A webpage is a representation of its current state.
REST Abstractions
- Consists of three main abstractions: Resources, Representations, and Actions
REST Resources
- Anything accessible and transferable between client and server
- Includes states and functions
- Examples include reviews from Metacritic, images from Imgur, videos from YouTube, and order information from Amazon
- Each resource must have a unique Uniform Resource Identifier (URI) within HTTP.
URI
- URIs are not meant to change over time.
- They're the only way to locate a resource, and if the URI changes, links to the resource do as well.
- URIs are used to negotiate the specific data representation the client desires.
- Clients define what specific data they want in the URI using parameters.
- Servers respond with the requested resource representation containing the needed data.
URI Structure
- URI format: scheme[userinfo@]host[:port]path[?query][#fragment]
- Example: https://[email protected]:123/forum/questions/?tag=networking&order=newest#top
- The ?query portion allows the client to specify parameters for which data the client wants.
Representations
- Items transferred between client and server
- Resources are not sent, only their representations
- Format determined by content-type (e.g., HTML, XML, JSON)
- How a representation interacts depends on the action on the resource.
REST Representations (Details)
- REST uses HTTP for communication between clients and servers
- Browser understands data transfer due to the TCP/IP protocol and the HTTP response header's Content-Type
- A representation can be in text, image, video, or JSON format, consistently using the same URI.
REST Representations (Examples)
- Data transfer as JSON instead of plain text (readability isn't essential)
- Video resolution relevant to the platform (720p for a mobile device)
Actions
- Used to operate on resources
- Examples include reviews for films, posting images, watching videos, deleting files
HTTP Actions
- Standard HTTP actions: GET, POST, PUT, DELETE
Data Actions and HTTP Equivalents
- CREATE equivalent to POST
- RETRIEVE equivalent to GET
- UPDATE equivalent to PUT
- DELETE equivalent to DELETE
HTTP as Uniform Interface
- Resource names are important in RESTful systems
- Four specific actions available for interacting with resources: Create, Retrieve, Update, and Delete (CRUD)
- This contrasts with other web applications, which lack standardized naming and implementation standards
Example 1: Instagram API
- Service URL: https://api.instagram.com/
- Resources represented as JSON files
- User URI: https://api.instagram.com/v1/users/{user-id}
- Search URI: https://api.instagram.com/v1/users/search
- Location URI: https://api.instagram.com/v1/locations/{location-id}
- Example query: http://api.instagram.com/v1/locations/search?accesstoken=ACCESS_TOKEN&lat=40.7127&lng=74.0059
Example 2: GitHub API
- Service URL: https://api.github.com/
- Resources represented as JSON files
- User URI: https://api.github.com/users/{user-id}
- Organization URI: https://api.github.com/orgs/{organization-id}
- Repository URI: https://api.github.com/repos/{repository-id}
- Example query: https://api.github.com/users/octocat
GET Method
- Used for retrieving resources
- Should not modify the resource
- Can be used repeatedly without changing the resource's state
- Can return parts of a resource
- Altering the URI can act as a query operation
POST Method
- Used for creating resources
- Resource URI usually unknown at creation time
- Server usually automatically generates the new URI for the resource
PUT Method
- Updates resource using a representation as a payload
- A GET request first obtain the representation of the resource to be updated
DELETE Method
- Deletes resources
- Similar to PUT in operation
- Atomic operations. A single DELETE request determines the final state.
- Can be used to determine the URI of the resource to be deleted.
HTTP Status Codes
- REST services use HTTP status codes (e.g., 200 OK, 404 Not Found, 500 Internal Server Error) to communicate the result of requests.
Security
- RESTful services have three main security methods: custom token authentication, HTTP Basic Authentication, and OAuth.
- OAuth is preferred for accessing services on behalf of users, but other methods control access to resources directly.
Custom Token Authentication
- Server generates a unique token for registered API users
- Registered users send the token with every request
- Token can be part of the URI or added to the HTTP request header
- Can be used for additional functionality like billing based on GET requests
Advantages and Disadvantages of Custom Tokens
- Advantages: independent token generation, easy implementation, logging data exchange.
- Disadvantages: insecure token-copying reuse without authorization.
HTTP Basic Authentication
- Clients send username and password pair (encoded in Base64) in the HTTP Authorization header.
- Client may receive 401 error if no username/password is provided
- Needs to be sent with every HTTP request for validation.
HTTP Basic Advantages and Disadvantages
- Advantages: manageable server authorization requests, reasonably secure with HTTPS (SSL).
- Disadvantages: not secure without HTTPS, Base64 encoding can be deciphered.
OAuth 2.0
- Preferred authorization scheme for RESTful services
- Easy integration, open-source protocol
- Allows third-party access to user data in a web service, with user consent, without exchanging username/password.
OAuth 2.0 Example
- User logs into game via Facebook
- Game accesses user data from Facebook
- Authorization granted by Facebook for the game application.
OAuth 2.0 Process
- User initiates Authorization Request
- Authorization Grant
- Access Token
- Protected Resource Access
Java REST Example
- Demonstrates a simple example (or examples) of a Java program or code related to RESTful Web Services.
GraphQL (Successor to REST)
- Open-source data query and manipulation language and runtime
- Developed internally at Facebook, publicly released in 2015
- Clients define the data structure required
- Returns exactly the structure requested from the server
- Potentially reduces data transferred compared to REST
GraphQL Design
- Models data as types and fields
- Functions for accessing data based on types and fields
- Queries validate against the defined fields and types
- Results returned in formats like JSON, XML, etc.
- Supports mutations for updating or creating data
GraphQL Examples
- Query example: retrieving hero's name
- Mutation example: creating a review
GraphQL Example Mutation Variables
- Example demonstrating how variables are passed to a mutation
GraphQL Example Mutation Result
- Demonstrates the format of the returned data from running a GraphQL mutation
GraphQL vs. REST
- GraphQL provides reflective discoverability (inspecting schema). REST uses hypermedia.
- GraphQL simplifies client-side work by reducing data fetching. REST uses caching.
GraphQL Conclusions
- GraphQL shifts server responsibilities to the client
- Aims for returning minimal data upon request
- Can be implemented along with REST(currently by GitHub)
- The suitability of GraphQL depends on the implementation quality of the REST system.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge on REST and GraphQL concepts with this quiz. Explore essential topics such as URIs, resource representations, and the fundamental characteristics of these API paradigms. Challenge yourself to distinguish key features and understand how they operate within web applications.