{new} PetStore
The PetStore
application is an functional application meant to demonstrate the following:
When you click the
http://localhost:10000/petstore
The contents of this page is primarily defined via annotations defined on the
The inner contents of the page are generated from this method which is used to define a jumping-off page for the application:
Note how we used the
The {@link oajr.helper.ResourceDescriptions} class used above is a convenience class for creating hyperlinks to child resources.
The application itself is defined in 3 packages:
org.apache.juneau.rest.examples.rest.petstore
org.apache.juneau.rest.examples.rest.petstore.dto
org.apache.juneau.rest.examples.rest.petstore.rest
We also define some static files in the org.apache.juneau.rest.examples.rest.petstore
package:
The
The DTOs are simply beans that combine both JPA and Juneau bean annotations:
The beans are found by JPA by adding them to the JPA persistence file.
The Petstore service is instantiated in our REST interface using a hook. Note that a real-world scenario would likely use some other means such as injection.
The Petstore database is empty by default.
The
http://localhost:10000/petstore/init
You can try loading the Petstore database using direct JPA or via REST calls through a client-side proxy.
The initialize page is rendered using the following methods in our
The direct initialization uses direct JPA to store beans in the database.
The following code in
The REST initialization uses a REST proxy interface to delete and store values in the database:
The
Note that this is the same interface used to define our server-side REST implementation! The annotations defined on the method parameters used for client-side proxies are also inherited by and used for our server-side implementation class.
The advantage to using a common interface for both your server-side and client-side APIs is that you have less of a chance of a mismatch between the server and client side definitions.
Now that we've initialized the contents of our database, we can start exploring the REST interface.
We can start by click the
http://localhost:10000/petstore/pet
Clicking on one of the ID links takes you to a details page:
http://localhost:10000/petstore/pet/1
You'll notice the details page shows bpx=
annotation on the
The hyperlinks and special rendering for
The
http://localhost:10000/petstore/pet/1
For example, selecting
http://localhost:10000/petstore/pet?plainText=true&Accept=application%2Fjson%2Bsimple
Note that we're using the convenience feature for specifying an Accept
header via a query parameter.
The
http://localhost:10000/petstore/pet/1
For example, selecting
http://localhost:10000/petstore/pet?stylesheet=htdocs%2Fthemes%2Flight.css
Both the
The implementation of a menu item contains methods for retrieving the label and HTML5 content of the menu item.
The
http://localhost:10000/petstore/pet
The converter will take the POJOs to be serialized and filter them based on the provided query/view/sort/paging attributes:
http://localhost:10000/petstore/pet?s=name%3DHoppy*&v=species%2Cname&o=name&p=0&l=20
The
http://localhost:10000/petstore/pet
Both the
The
http://localhost:10000/petstore/pet?method=OPTIONS
Since we've defined tags on our annotations, the pet-related operations are all grouped under the
Information for all HTTP parts is automatically generated:
The schema models for POJO models is available in the
Auto-generated examples are available for all supported languages:
For example,
Examples can be derived in a number of ways. In our case, we've defined a static method on our
Similar functionality exists for request bodies as well:
At the bottom of the page is a listing of the POJO models in the app:
The
http://localhost:10000/petstore/photos
The
The contents of the home page simply renders our collection of photo beans:
Clicking on one of the hyperlinks renders the stored image for us:
http://localhost:10000/petstore/photos/cat
The method for retrieving images simply returns a
The
Likewise, the body of requests can also be instances of
The
A custom menu item is provided for uploading new images:
http://localhost:10000/petstore/photos
The menu item is defined as a
The menu item then submits multi-part form posts to the following method:
The
http://localhost:10000/petstore/sql
For example, viewing all of the
http://localhost:10000/petstore/sql?sql=select+*+from+PetstorePet
The
The connection information is pulled from the
The query entry page is rendered using HTML5 beans:
The form then submits its results to the following method using a form input bean:
Note that we could have also used