Lecture 10 - Implementing REST Flashcards

1
Q

Is Jakarta RESTful Web Services (JAX-RS) part of the Jakarta EE spec?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What JAX-RS annotation defines URI mappings and templates?

A

@Path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What 2 JAX-RS annotations define the resource to produce and consume?

A

@Produces
@Consumes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What 5 JAX-RS annotations identifies which HTTP method a Java method is interested in?

A

@GET
@POST
@DELETE
@PUT
@HEADER

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a JAX-RS parameter annotation?

A

In JAX-RS (Java API for RESTful Web Services), parameter annotations are used to extract data from an HTTP request and pass it to resource methods.

@PathParam
@QueryParam
@HeaderParam
@CookieParam
@MatrixParam
@Context (deprecated)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Example of a form that uses JAX-RS

A

@Path(“/categories”)
public interface CategoryService {

@GET
@Path(“{id}”)
@Produces(MediaType.APPLICATION_JSON)
Category find(@PathParam(“id”) int id);
@POST
@Consumes(MediaType.APPLICATION_JSON)
void persist(Category category);
@PUT
@Consumes(MediaType.APPLICATION_JSON)
void merge(Category category);
@DELETE
@Path(“{id}”)
void remove(@PathParam(“id”) int id);
@GET
@Produces(MediaType.APPLICATION_JSON)
Category[] getAll();

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to GET and POST work?

A

GET Requests: Data is passed through the URI as path parameters or query parameters.

Path parameters are embedded directly within the URL path (e.g., /users/{id})

POST Requests: Data is usually not passed in the URI but instead in the request body.

This is often the case when submitting forms with more complex data, such as JSON objects.
The URI is still used to specify the endpoint (e.g., /users), but the actual data is placed in the request body rather than in the URL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a JAX-RS Response and ResponseBuilder class used for?

A

Customizes HTTP response messages that go back to client (ex: 404 not found)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do we set the context root of our RESTful service (2 ways)?

A

Extend jakarta.ws.rs.core.Application
Annotate class with @ApplicationPath(“/api”)

OR

Use servlet-mapping tag in web.xml

<servlet-mapping>
<servlet-name>
jakarta.ws.rs.core.Application
...
</servlet-name></servlet-mapping>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What beans can JAX-RS annotations be used on?

A

Stateless session
Singleton session
NOT stateful session beans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are MessageBodyReader/Writers?

A

In JAX-RS (Java API for RESTful Web Services), MessageBodyReader and MessageBodyWriter are interfaces that handle the serialization and deserialization of HTTP request and response bodies. These are essential for converting data between Java objects and HTTP message bodies (e.g., JSON, XML, or text), enabling easy data exchange between the client and server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do we set up a client object for use in our back end?

A

Client client = ClientBuilder.newClient();
Response res = client.target(“http://example.org/hello”)
.request(“text/plain”).get();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What 3 security services are provided with RESTful services?

A

Authentication, authorization, encryption

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do we enforce security in JAX-RS?

A

<security-constraint> element in web.xml
</security-constraint>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly