本文整理了Java中io.micronaut.http.HttpResponse.ok()
方法的一些代码示例,展示了HttpResponse.ok()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.ok()
方法的具体详情如下:
包路径:io.micronaut.http.HttpResponse
类名称:HttpResponse
方法名:ok
[英]Return an io.micronaut.http.HttpStatus#OK response with an empty body.
[中]返回一个io。微纳特。http。HttpStatus#空主体的正常响应。
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public HttpResponse handle(HttpRequest request, OutOfStockException exception) {
return HttpResponse.ok(0);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public HttpResponse handle(HttpRequest request, OutOfStockException exception) {
return HttpResponse.ok(0);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* Lookup the response from the context.
*
* @param request The context
* @return The {@link NettyMutableHttpResponse}
*/
@Internal
public static NettyMutableHttpResponse getOrCreate(NettyHttpRequest<?> request) {
return getOr(request, io.micronaut.http.HttpResponse.ok());
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Get(value = "/ok-with-body", produces = MediaType.TEXT_PLAIN)
public HttpResponse okWithBody() {
return HttpResponse.ok("some text");
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Get
public HttpResponse index(String username) {
return HttpResponse.ok("Authenticated: " + username);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Error(exception = OutOfStockException.class, global = true)
public HttpResponse handleOutOfStock(HttpRequest request) {
return HttpResponse.ok(-1);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Get("/ok")
public HttpResponse ok() {
return HttpResponse.ok();
}
代码示例来源:origin: micronaut-projects/micronaut-core
MutableHttpResponse<Object> ok = HttpResponse.ok();
handleResponse(request, ok);
return Optional.of(ok);
代码示例来源:origin: micronaut-projects/micronaut-core
@Get("/{isbn}")
public HttpResponse find(String isbn) {
if (isbn.equals("1680502395")) {
Map<String, Object> m = new HashMap<>();
m.put("status", 401);
m.put("error", "Unauthorized");
m.put("message", "No message available");
m.put("path", "/books/"+isbn);
return HttpResponse.status(HttpStatus.UNAUTHORIZED).body(m);
}
return HttpResponse.ok(new Book("1491950358", "Building Microservices"));
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Get("/{id}")
public HttpResponse<Story> get(String id) {
Story story = new Story();
story.setId(id);
return HttpResponse.ok(story);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
List<HttpFilter> filters = router.findFilters(msg);
AtomicReference<HttpRequest<?>> requestReference = new AtomicReference<>(msg);
MutableHttpResponse<?> proceed = HttpResponse.ok();
Publisher<MutableHttpResponse<?>> routePublisher = Flowable.create(emitter -> {
emitter.onNext(proceed);
代码示例来源:origin: micronaut-projects/micronaut-core
@Get("/custom-headers")
public HttpResponse customHeaders() {
return HttpResponse.ok("abc").contentType("text/plain").contentLength(7);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Get("/ok-with-body-object")
public HttpResponse<Foo> okWithBodyObject() {
return HttpResponse.ok(new Foo("blah", 10))
.headers((headers)->
headers.contentType(MediaType.APPLICATION_JSON_TYPE)
);
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Get("/{name}")
public HttpResponse<Pet> get(String name, @Header("X-Pet-Client") String clientId) {
Pet pet = new Pet();
pet.setName(name);
pet.setAge(Integer.valueOf(clientId));
return HttpResponse.ok(pet)
.header("X-Pet-Client", clientId);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
final RouteMatch<?> routeMatch = !finalRoute.isExecutable() ? requestArgumentSatisfier.fulfillArgumentRequirements(finalRoute, requestReference.get(), true) : finalRoute;
Object result = routeMatch.execute();
MutableHttpResponse<Object> chunkedResponse = HttpResponse.ok(result);
chunkedResponse.header(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
emitter.onNext(chunkedResponse);
代码示例来源:origin: micronaut-projects/micronaut-examples
@Post("/send")
public HttpResponse send(@Valid @Body Email email) {
log.info(email.toString());
if ( emailService == null ) {
log.warn("Email service not injected");
return HttpResponse.serverError();
}
emailService.send(email);
return HttpResponse.ok();
}
}
代码示例来源:origin: io.micronaut/http-server
MutableHttpResponse<Object> ok = HttpResponse.ok();
handleResponse(request, ok);
return Optional.of(ok);
内容来源于网络,如有侵权,请联系作者删除!