This is a base code to improve implementation velocity to implement Jax-RS APIs.
With tt you get all default REST routes for your API just extending the BaseApi
class and implementing some methods.
JAX-RS is very verbose to define the routes and this is repeated to each API you want to provide. All REST resources have the same interface:
REST routes to resource
HTTP Verb | Path | Action | Used for | API Method |
---|---|---|---|---|
GET | /resources | index (list) | display a list of all resource items | list |
POST | /resources | create | create a new resource item | create |
GET | /resources/:id | show | display a specific resource item | show |
PUT | /resources/:id | update | update a specific resource item | update |
DELETE | /resources/:id | destroy | delete a specific resource item | delete |
Thus, with this project you dont need to re-write the routes definition to each resource API, just implement what they do.
Ruby on Rails is a very good example of the easyness to implement a API's controller when using conventions.
Yout API must extend the abastract class BaseApi
, implementing its abstract methods.
Also, the exceptions you want to throw in API must extend ApiException
.
Maven Dependency Add to your pom.xml:
<dependency> <groupId>br.danielcastellani</groupId> <artifactId>base-jax-rs-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
Get Dependency Since it is not on Maven Central, yet, you must run in your machine:
git clone https://github.com/dancastellani/jax-rs-base-api.git cd jax-rs-base-api mvn install
JAX-RS-Base-Api has a abastract class BaseApi
and a exception ApiException
.
The BaseApi
defines the routes above for each API that extends it.
Each route calls a abstract method that must be implemented. These methods are:
- list()
- show(int i)
- create(T t)
- delete(int i)
- update(Integer intgr, T t)