Skip to content

Commit

Permalink
Add support for DELETE endpoints (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
bavardage authored Mar 3, 2022
1 parent d9e53cd commit 729e6a8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public HttpMethod method() {
case "GET" -> HttpMethod.GET;
case "PUT" -> HttpMethod.PUT;
case "POST" -> HttpMethod.POST;
case "DELETE" -> HttpMethod.DELETE;
default -> throw new IllegalStateException(
"Unsupported HTTP method " + endpoint.method());
};
Expand Down
3 changes: 2 additions & 1 deletion barista/src/main/java/com/markelliot/barista/HttpMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
public enum HttpMethod {
GET(Methods.GET),
PUT(Methods.PUT),
POST(Methods.POST);
POST(Methods.POST),
DELETE(Methods.DELETE);

private final HttpString method;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ private <Request, Response> HttpHandler authEndpoint(
Endpoints.VerifiedAuth<Request, Response> endpoint) {
return switch (endpoint.method()) {
case GET -> exchange -> authNoBody(endpoint, exchange);
case PUT, POST -> withBody((exchange, body) -> authWithBody(endpoint, exchange, body));
case PUT, POST, DELETE -> withBody(
(exchange, body) -> authWithBody(endpoint, exchange, body));
};
}

public <Request, Response> HttpHandler openEndpoint(
Endpoints.Open<Request, Response> endpoint) {
return switch (endpoint.method()) {
case GET -> exchange -> openNoBody(endpoint, exchange);
case PUT, POST -> withBody((exchange, body) -> openWithBody(endpoint, exchange, body));
case PUT, POST, DELETE -> withBody(
(exchange, body) -> openWithBody(endpoint, exchange, body));
};
}

Expand Down

0 comments on commit 729e6a8

Please sign in to comment.