Skip to content

Http Methods

Thiago Bustamante edited this page Jan 20, 2019 · 3 revisions

Http Methods

We have decorators for each HTTP method. Theses decorators are used on service methods already bound to a Path route to specify the endpoint at which requests can be made.

The following decorators can be used:

Decorator Description
@GET For HTTP GET operation
@POST For HTTP POST operation
@PUT For HTTP PUT operation
@PATCH For HTTP PATCH operation
@DELETE For HTTP DELETE operation
@OPTIONS For HTTP OPTIONS operation
@HEAD For HTTP HEAD operation

Some examples:

@Path("/users")
class UserService {
   @GET
   getUsers(): Promise<Array<User>> {
      //...
   }

   @GET
   @Path(":userId")
   getUser(@PathParam("userId")): Promise<User> {
      //...
   }

   @PUT
   @Path(":userId")
   saveUser(@PathParam("userId"), user: User): void {
      //...
   }
}

Only methods decorated with one of this HTTP method decorators are exposed as handlers for requests on the server.

A single method can only be decorated with one of those decorators at a time.