Search in sources :

Example 1 with UriTemplate

use of io.micronaut.http.uri.UriTemplate in project micronaut-core by micronaut-projects.

the class BookmarkControllerSpec method testBindingPagination.

@Test
public void testBindingPagination() {
    UriTemplate template = new UriTemplate("/api/bookmarks/list{?offset,max,sort,order}");
    Map<String, Object> params = new HashMap<>();
    params.put("offset", 0);
    params.put("max", 10);
    HttpResponse response = client.toBlocking().exchange(template.expand(params));
    assertEquals(HttpStatus.OK, response.status());
}
Also used : HashMap(java.util.HashMap) HttpResponse(io.micronaut.http.HttpResponse) UriTemplate(io.micronaut.http.uri.UriTemplate) Test(org.junit.Test)

Example 2 with UriTemplate

use of io.micronaut.http.uri.UriTemplate in project micronaut-core by micronaut-projects.

the class DeleteEndpointRouteBuilder method registerRoute.

@Override
protected void registerRoute(ExecutableMethod<?, ?> method, String id, Integer port) {
    Class<?> declaringType = method.getDeclaringType();
    UriTemplate template = buildUriTemplate(method, id);
    UriRoute uriRoute = DELETE(template.toString(), declaringType, method.getMethodName(), method.getArgumentTypes());
    if (port != null) {
        uriRoute = uriRoute.exposedPort(port);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Created Route to @Endpoint {}: {}", method.getDeclaringType().getName(), uriRoute);
    }
}
Also used : UriRoute(io.micronaut.web.router.UriRoute) UriTemplate(io.micronaut.http.uri.UriTemplate)

Example 3 with UriTemplate

use of io.micronaut.http.uri.UriTemplate in project micronaut-core by micronaut-projects.

the class ReadEndpointRouteBuilder method registerRoute.

@Override
protected void registerRoute(ExecutableMethod<?, ?> method, String id, Integer port) {
    Class<?> declaringType = method.getDeclaringType();
    UriTemplate template = buildUriTemplate(method, id);
    UriRoute uriRoute = GET(template.toString(), declaringType, method.getMethodName(), method.getArgumentTypes());
    if (port != null) {
        uriRoute = uriRoute.exposedPort(port);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Created Route to @Endpoint {}: {}", method.getDeclaringType().getName(), uriRoute);
    }
    uriRoute = HEAD(template.toString(), declaringType, method.getMethodName(), method.getArgumentTypes());
    if (port != null) {
        uriRoute = uriRoute.exposedPort(port);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Created Route to @Endpoint {}: {}", method.getDeclaringType().getName(), uriRoute);
    }
}
Also used : UriRoute(io.micronaut.web.router.UriRoute) UriTemplate(io.micronaut.http.uri.UriTemplate)

Example 4 with UriTemplate

use of io.micronaut.http.uri.UriTemplate in project micronaut-core by micronaut-projects.

the class WriteEndpointRouteBuilder method registerRoute.

@Override
protected void registerRoute(ExecutableMethod<?, ?> method, String id, Integer port) {
    Class<?> declaringType = method.getDeclaringType();
    UriTemplate template = buildUriTemplate(method, id);
    String[] consumes = method.stringValues(Write.class, "consumes");
    UriRoute uriRoute = POST(template.toString(), declaringType, method.getMethodName(), method.getArgumentTypes()).consumes(MediaType.of(consumes));
    if (port != null) {
        uriRoute = uriRoute.exposedPort(port);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Created Route to @Endpoint {}: {}", method.getDeclaringType().getName(), uriRoute);
    }
}
Also used : UriRoute(io.micronaut.web.router.UriRoute) UriTemplate(io.micronaut.http.uri.UriTemplate)

Example 5 with UriTemplate

use of io.micronaut.http.uri.UriTemplate in project micronaut-core by micronaut-projects.

the class MovieTicketControllerSpec method testBindingBean.

@Test
public void testBindingBean() {
    UriTemplate template = new UriTemplate("/api/movie/ticket/terminator{?minPrice,maxPrice}");
    Map<String, Object> params = new HashMap<>();
    params.put("minPrice", 5.0);
    params.put("maxPrice", 20.0);
    HttpResponse response = client.toBlocking().exchange(template.expand(params));
    assertEquals(HttpStatus.OK, response.status());
}
Also used : HashMap(java.util.HashMap) HttpResponse(io.micronaut.http.HttpResponse) UriTemplate(io.micronaut.http.uri.UriTemplate) Test(org.junit.Test)

Aggregations

UriTemplate (io.micronaut.http.uri.UriTemplate)5 UriRoute (io.micronaut.web.router.UriRoute)3 HttpResponse (io.micronaut.http.HttpResponse)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2