Projets
Pages enfant
  • 3.12.1 Ecrire le service REST à exposer

Comparaison des versions

Légende

  • Ces lignes ont été ajoutées. Ce mot a été ajouté.
  • Ces lignes ont été supprimées. Ce mot a été supprimé.
  • La mise en forme a été modifiée.
Commentaire: Migrated to Confluence 4.0

Sommaire :

Sommaire
maxLevel3

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.

Utilisation

En JAX-RS il est très simple d'exposer la couche métier sous forme d'un service REST. Cela revient à utiliser des annotations au niveau de l'interface DomainService :

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();
.../...

Pour avoir plus d'information sur les annotations JAX-RS Cf.JAX-RS : Understanding the Basics

Exemple d'utilisation

Un get sur /cxf/rest/domainService/users/colmant donnera :

Bloc de code
langjavascript
{
 "language":"fr",
 "id":"colmant",
 "displayName":"Y Colmant",
 "informations":
  [
   {
    "id":53,
    "informationKey":"INSERT_DATE",
    "informationValue":"2011/06/10 12:57:27"
   }
  ],
 "admin":false
}