Sommaire :
...
Introduction
Esup-commons V2 utilise la norme JAX-RS pour exposer la couche métier en REST. L'implémentation utilisée est celle offerte pour CXF.
...
| Bloc de code |
|---|
@Path("/domainService/")
@Produces("application/json")
public interface DomainService extends Serializable {
.../...
@GET
@Path("/users/{id}")
User getUser(@PathParam("id") String id) throws UserNotFoundException;
.../...
@GET
@Path("/users")
List<User> getUsers();
.../...
@DELETE
@Path("/users/{id}")
void deleteUser(@PathParam("id") String id);
.../...
@PUT
@Path("/users")
void addUser(User user);
.../... |
Pour avoir plus d'information sur les annotations JAX-RS Cf.JAX-RS : Understanding the Basics
...
Exemple d'utilisation
...
Ajout
| Bloc de code |
|---|
|
[
curl -X PUT \
-
H 'Content-Type: {application/json' \
-d '{"language":"fr","id":"colmant","displayName":"Y Colmant","informations":[{"informationKey":"TRUC","informationValue":"machin"},{"informationKey":"TRUC2","informationValue":"machin2"}],"admin":false }' \
http://localhost:8080/cxf/rest/domainService/users |
Lecture
| Bloc de code |
|---|
|
curl -X GET \
-H 'Content-Type: application/json' \
http://localhost:8080/cxf/rest/domainService/users |
Renvoie
| Bloc de code |
|---|
|
[
{"language": "fr",
"id": "colmant",
"displayName" language: "fr"
id: "bourges"
displayName: "R Bourges"
-
informations: [
-
{
id: 52
informationKey: "INSERT_DATE"
informationValue: "2011/06/10 12:57:13"
}
-
{
id: 54
informationKey: "UPDATE_DATE"
informationValue: "2011/06/10 18:21:46"
}
]
admin: false
}
-
{
language: "fr"
id: "colmant"
displayName: "Y Colmant",
-"admin": false,
informations"informations": [
{"id": 22,
-"informationValue": "machin",
"informationKey": "TRUC"
{},
id: 53{"id": 23,
"informationValue": "machin2",
"informationKey": "INSERT_DATETRUC2"
},
{"id": 24,
"informationValue": "20112013/0603/1001 1217:57:2701",
"informationKey": "INSERT_DATE"
}
]
}
] |
On note que l'on a un item supplémentaire pour informations. C'est le code métier de l'application qui l'a ajouté
Suppression
| Bloc de code |
|---|
curl -X DELETE ]\
-H 'Content-Type: admin: false
application/json' \
}
]http://localhost:8080/cxf/rest/domainService/users/colmant |