Package org.apache.juneau.petstore.rest
Class PetStoreResource
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.apache.juneau.rest.server.servlet.RestServlet
org.apache.juneau.rest.server.servlet.BasicRestServlet
org.apache.juneau.petstore.rest.PetStoreResource
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable,BasicUniversalConfig,DefaultConfig,DefaultHtmlConfig
Petstore CRUD REST resource.
Deployment-agnostic. Mounted by both juneau-petstore-jetty and juneau-petstore-springboot via
the @Rest(children=...) of their root router.
Endpoints:
GET /pets— list petsGET /pets/{id}— get petPOST /pets— create petPUT /pets/{id}— update petDELETE /pets/{id}— delete petGET /pets/{id}/photo— get pet photoPUT /pets/{id}/photo— upload pet photoGET /orders— list ordersGET /orders/{id}— get orderPOST /orders— create orderPUT /orders/{id}— update orderDELETE /orders/{id}— delete orderGET /users— list usersGET /users/{username}— get userPOST /users— create userPUT /users/{username}— update userDELETE /users/{username}— delete user
See Also:
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.juneau.rest.server.servlet.RestServlet
RestServlet.Builder<R extends RestServlet,SELF extends RestServlet.Builder<R, SELF>>, RestServlet.DefaultBuilder<R extends RestServlet> -
Field Summary
Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateOrder(Order order) Creates a new order.Creates a new pet.createUser(User user) Creates a new user.voiddeleteOrder(long id) Deletes an order by ID.voiddeletePet(long id) Deletes a pet by ID.voiddeleteUser(String username) Deletes a user by username.getOrder(long id) Retrieves an order by ID.Lists all orders.getPet(long id) Retrieves a pet by ID.getPetPhoto(long id) Retrieves the uploaded photo for a pet.getPets()Lists all pets.Retrieves a user by username.getUsers()Lists all users.putPetPhoto(long id, BufferedImage image) Uploads a photo for a pet.updateOrder(long id, Order order) Updates an existing order.Updates an existing pet.updateUser(String username, User user) Updates an existing user.Methods inherited from class org.apache.juneau.rest.server.servlet.RestServlet
builder, createAuthenticator, destroy, doLog, getContext, getPath, getPaths, getRequest, getResponse, getRestBuilder, init, log, log, service, setContextMethods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, isSensitiveHeader, serviceMethods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
PetStoreResource
public PetStoreResource()
-
-
Method Details
-
getPets
Lists all pets.- Returns:
- All pets.
-
getPet
Retrieves a pet by ID.- Parameters:
id- The pet ID.- Returns:
- The pet.
- Throws:
NotFound- If no pet with the given ID exists.
-
createPet
Creates a new pet.- Parameters:
pet- The pet to create.- Returns:
- The created pet (with assigned ID).
-
updatePet
Updates an existing pet.- Parameters:
id- The pet ID.pet- The replacement pet body.- Returns:
- The updated pet.
- Throws:
NotFound- If no pet with the given ID exists.
-
deletePet
Deletes a pet by ID.- Parameters:
id- The pet ID.- Throws:
NotFound- If no pet with the given ID exists.
-
getPetPhoto
Retrieves the uploaded photo for a pet.- Parameters:
id- The pet ID.- Returns:
- The photo image.
- Throws:
NotFound- If no pet with the given ID exists, or no photo has been uploaded for it.
-
putPetPhoto
Uploads a photo for a pet.On success, also updates the pet's
photofield to point back at this endpoint.- Parameters:
id- The pet ID.image- The photo image.- Returns:
- OK.
- Throws:
NotFound- If no pet with the given ID exists.
-
getOrders
Lists all orders.- Returns:
- All orders.
-
getOrder
Retrieves an order by ID.- Parameters:
id- The order ID.- Returns:
- The order.
- Throws:
NotFound- If no order with the given ID exists.
-
createOrder
Creates a new order.- Parameters:
order- The order to create.- Returns:
- The created order (with assigned ID).
-
updateOrder
Updates an existing order.- Parameters:
id- The order ID.order- The replacement order body.- Returns:
- The updated order.
- Throws:
NotFound- If no order with the given ID exists.
-
deleteOrder
Deletes an order by ID.- Parameters:
id- The order ID.- Throws:
NotFound- If no order with the given ID exists.
-
getUsers
Lists all users.- Returns:
- All users.
-
getUser
Retrieves a user by username.- Parameters:
username- The username.- Returns:
- The user.
- Throws:
NotFound- If no user with the given username exists.
-
createUser
Creates a new user.- Parameters:
user- The user to create. Must carry a non-null username not already in use.- Returns:
- The created user.
-
updateUser
Updates an existing user.The body replaces the user, except that the write-only password is kept when the body has none (or a blank one), so a GET followed by a PUT of the same body does not erase it.
- Parameters:
username- The username.user- The replacement user body.- Returns:
- The updated user.
- Throws:
NotFound- If no user with the given username exists.
-
deleteUser
Deletes a user by username.- Parameters:
username- The username.- Throws:
NotFound- If no user with the given username exists.
-