Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint factory methods for head, patch and trace #2132

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions zio-http/src/main/scala/zio/http/codec/MethodCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ private[codec] trait MethodCodecs {

def connect: HttpCodec[Method, Unit] = method(zio.http.Method.CONNECT)
def delete: HttpCodec[Method, Unit] = method(zio.http.Method.DELETE)
def head: HttpCodec[Method, Unit] = method(zio.http.Method.HEAD)
def get: HttpCodec[Method, Unit] = method(zio.http.Method.GET)
def options: HttpCodec[Method, Unit] = method(zio.http.Method.OPTIONS)
def patch: HttpCodec[Method, Unit] = method(zio.http.Method.PATCH)
def post: HttpCodec[Method, Unit] = method(zio.http.Method.POST)
def put: HttpCodec[Method, Unit] = method(zio.http.Method.PUT)
def trace: HttpCodec[Method, Unit] = method(zio.http.Method.TRACE)
}
54 changes: 47 additions & 7 deletions zio-http/src/main/scala/zio/http/endpoint/Endpoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ final case class Endpoint[Input, Err, Output, Middleware <: EndpointMiddleware](
object Endpoint {

/**
* Constructs an endpoint for an HTTP DELETE endpoint, whose path is described
* Constructs an endpoint for an HTTP DELETE method, whose path is described
* by the specified path codec.
*/
def delete[Input](path: PathCodec[Input]): Endpoint[Input, ZNothing, ZNothing, EndpointMiddleware.None] = {
Expand All @@ -251,7 +251,7 @@ object Endpoint {
}

/**
* Constructs an endpoint for an HTTP GET endpoint, whose path is described by
* Constructs an endpoint for an HTTP GET method, whose path is described by
* the specified path codec.
*/
def get[Input](path: PathCodec[Input]): Endpoint[Input, ZNothing, ZNothing, EndpointMiddleware.None] =
Expand All @@ -264,8 +264,22 @@ object Endpoint {
)

/**
* Constructs an endpoint for an HTTP OPTIONS endpoint, whose path is
* described by the specified path codec.
* Constructs an endpoint for an HTTP HEAD method, whose path is described by
* the specified path codec.
*/
def head[Input](path: PathCodec[Input]): Endpoint[Input, ZNothing, ZNothing, EndpointMiddleware.None] = {
Endpoint(
path ++ MethodCodec.head,
HttpCodec.unused,
HttpCodec.unused,
Doc.empty,
EndpointMiddleware.None,
)
}

/**
* Constructs an endpoint for an HTTP OPTIONS method, whose path is described
* by the specified path codec.
*/
def options[Input](path: PathCodec[Input]): Endpoint[Input, ZNothing, ZNothing, EndpointMiddleware.None] =
Endpoint(
Expand All @@ -277,8 +291,21 @@ object Endpoint {
)

/**
* Constructs an endpoint for an HTTP POST endpoint, whose path is described
* by the specified path codec.
* Constructs an endpoint for an HTTP PATCH method, whose path is described by
* the specified path codec.
*/
def patch[Input](path: PathCodec[Input]): Endpoint[Input, ZNothing, ZNothing, EndpointMiddleware.None] =
Endpoint(
path ++ MethodCodec.patch,
HttpCodec.unused,
HttpCodec.unused,
Doc.empty,
EndpointMiddleware.None,
)

/**
* Constructs an endpoint for an HTTP POST method, whose path is described by
* the specified path codec.
*/
def post[Input](path: PathCodec[Input]): Endpoint[Input, ZNothing, ZNothing, EndpointMiddleware.None] =
Endpoint(
Expand All @@ -290,7 +317,7 @@ object Endpoint {
)

/**
* Constructs an endpoint for an HTTP PUT endpoint, whose path is described by
* Constructs an endpoint for an HTTP PUT method, whose path is described by
* the specified path codec.
*/
def put[Input](path: PathCodec[Input]): Endpoint[Input, ZNothing, ZNothing, EndpointMiddleware.None] =
Expand All @@ -302,6 +329,19 @@ object Endpoint {
EndpointMiddleware.None,
)

/**
* Constructs an endpoint for an HTTP TRACE method, whose path is described by
* the specified path codec.
*/
def trace[Input](path: PathCodec[Input]): Endpoint[Input, ZNothing, ZNothing, EndpointMiddleware.None] =
Endpoint(
path ++ MethodCodec.trace,
HttpCodec.unused,
HttpCodec.unused,
Doc.empty,
EndpointMiddleware.None,
)

final case class OutErrors[Input, Err, Output, Middleware <: EndpointMiddleware, Err2](
self: Endpoint[Input, Err, Output, Middleware],
) extends AnyVal {
Expand Down