package http4s
- Source
- package.scala
- Alphabetic
- By Inheritance
- http4s
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Package Members
- package headers
- package internal
- package metrics
- package multipart
This package is the start of a multipart implementation for http4s.
This package is the start of a multipart implementation for http4s. It is still deficient in a few ways:
- All encoding is chunked transfers, except for entities small enough to fit into the blaze buffer. This irritates some server implementations.
- When decoding, chunks are kept in memory. Large ones should be buffered to a temp file.
- It's a bit handwavy around character sets. Things probably go horribly wrong if you're not UTF-8.
- This module is lightly tested, and its API should be considered experimental.
Enter this package at your own risk, but we'd love the feedback.
- package syntax
- package util
- package websocket
Type Members
- type AuthScheme = CIString
- type AuthedRequest[F[_], T] = ContextRequest[F, T]
- type AuthedRoutes[T, F[_]] = Kleisli[[β$1$]OptionT[F, β$1$], AuthedRequest[F, T], Response[F]]
The type parameters need to be in this order to make partial unification trigger.
The type parameters need to be in this order to make partial unification trigger. See https://github.com/http4s/http4s/issues/1506
- final case class BasicCredentials(username: String, password: String, charset: java.nio.charset.Charset = StandardCharsets.UTF_8) extends Product with Serializable
- sealed trait CacheDirective extends Product with Renderable
- type Callback[A] = (Either[Throwable, A]) => Unit
- final case class Challenge(scheme: String, realm: String, params: Map[String, String] = Map.empty) extends Renderable with Product with Serializable
- final case class Charset extends Renderable with Product with Serializable
- sealed abstract class CharsetRange extends HasQValue with Renderable
- class ContentCoding extends HasQValue with Ordered[ContentCoding] with Renderable
- final case class ContextRequest[F[_], A](context: A, req: Request[F]) extends Product with Serializable
- final case class ContextResponse[F[_], A](context: A, response: Response[F]) extends Product with Serializable
- type ContextRoutes[T, F[_]] = Kleisli[[β$2$]OptionT[F, β$2$], ContextRequest[F, T], Response[F]]
- sealed abstract class Credentials extends Renderable
- trait DecodeFailure extends RuntimeException with MessageFailure
Indicates a problem decoding a Message.
Indicates a problem decoding a Message. This may either be a problem with the entity headers or with the entity itself.
- type DecodeResult[F[_], A] = EitherT[F, DecodeFailure, A]
- final case class Entity[+F[_]](body: EntityBody[F], length: Option[Long] = None) extends Product with Serializable
- type EntityBody[+F[_]] = Stream[F, Byte]
- trait EntityDecoder[F[_], T] extends AnyRef
A type that can be used to decode a Message EntityDecoder is used to attempt to decode a Message returning the entire resulting A.
A type that can be used to decode a Message EntityDecoder is used to attempt to decode a Message returning the entire resulting A. If an error occurs it will result in a failed effect. The default decoders provided here are not streaming, but one could implement a streaming decoder by having the value of A be some kind of streaming construct.
- T
result type produced by the decoder
- Annotations
- @implicitNotFound()
- trait EntityEncoder[F[_], A] extends AnyRef
- Annotations
- @implicitNotFound()
- final case class EntityTag(tag: String, weakness: Weakness = Strong) extends Renderable with Product with Serializable
- type EventStream[F[_]] = Stream[F, ServerSentEvent]
A stream of server-sent events
- sealed trait FormDataDecoder[A] extends AnyRef
A decoder ware that uses QueryParamDecoder to decode values in org.http4s.UrlForm
A decoder ware that uses QueryParamDecoder to decode values in org.http4s.UrlForm
scala> import cats.syntax.all._ scala> import cats.data._ scala> import org.http4s.FormDataDecoder._ scala> import org.http4s.ParseFailure scala> case class Foo(a: String, b: Boolean) scala> case class Bar(fs: List[Foo], f: Foo, d: Boolean) scala> scala> implicit val fooMapper: FormDataDecoder[Foo] = ( | field[String]("a"), | field[Boolean]("b") | ).mapN(Foo.apply) scala> scala> val barMapper = ( | list[Foo]("fs"), | nested[Foo]("f"), | field[Boolean]("d") | ).mapN(Bar.apply) scala> scala> barMapper( | Map( | "fs[].a" -> Chain("a1", "a2"), | "fs[].b" -> Chain("true", "false"), | "f.a" -> Chain("fa"), | "f.b" -> Chain("false"), | "d" -> Chain("true")) | ) res1: ValidatedNel[ParseFailure, Bar] = Valid(Bar(List(Foo(a1,true), Foo(a2,false)),Foo(fa,false),true))
The companion object provides a EntityDecoder from HTML form parameters.
, import org.http4s.FormDataDecoder.formEntityDecoder HttpRoutes .of[F] { case req @ POST -> Root => req.as[MyEntity].flatMap { entity => Ok() } }
For more examples, check the tests https://github.com/http4s/http4s/blob/main/tests/src/test/scala/org/http4s/FormDataDecoderSpec.scala
Examples: - trait HasQValue extends AnyRef
- trait Header[A, T <: Type] extends AnyRef
Typeclass representing an HTTP header, which all the http4s default headers satisfy.
Typeclass representing an HTTP header, which all the http4s default headers satisfy. You can add modelled headers by providing an implicit instance of
Header[YourModelledHeader]
- final class Headers extends AnyVal
A collection of HTTP Headers
- type Http[F[_], G[_]] = Kleisli[F, Request[G], Response[G]]
- final case class Http4sVersion(major: Int, minor: Int) extends Product with Serializable
- type HttpApp[F[_]] = Kleisli[F, Request[F], Response[F]]
A kleisli with a Request input and a Response output, such that the response effect is the same as the request and response bodies'.
- trait HttpCodec[A] extends Renderer[A]
- class HttpDate extends Renderable with Ordered[HttpDate]
An HTTP-date value represents time as an instance of Coordinated Universal Time (UTC).
An HTTP-date value represents time as an instance of Coordinated Universal Time (UTC). It expresses time at a resolution of one second. By using it over java.time.Instant in the model, we assure that if two headers render equally, their values are equal.
- type HttpRoutes[F[_]] = Kleisli[[β$0$]OptionT[F, β$0$], Request[F], Response[F]]
A kleisli with a Request input and a Response output, such that the response effect is an optional inside the effect of the request and response bodies.
- final case class HttpVersion extends Renderable with Ordered[HttpVersion] with Product with Serializable
HTTP's version number consists of two decimal digits separated by a "." (period or decimal point).
HTTP's version number consists of two decimal digits separated by a "." (period or decimal point). The first digit ("major version") indicates the messaging syntax, whereas the second digit ("minor version") indicates the highest minor version within that major version to which the sender is conformant (able to understand for future communication).
- See also
- final case class InvalidBodyException(msg: String) extends Exception with NoStackTrace with Product with Serializable
Exception dealing with invalid body
Exception dealing with invalid body
- msg
description if what makes the body invalid
- final case class InvalidMessageBodyFailure(details: String, cause: Option[Throwable] = None) extends RuntimeException with MessageBodyFailure with Product with Serializable
Indicates a semantic error decoding the body of an HTTP Message.
- final case class InvalidResponseException(msg: String) extends Exception with NoStackTrace with Product with Serializable
Exception dealing with invalid response
Exception dealing with invalid response
- msg
description if what makes the response invalid
- final case class LanguageTag(primaryTag: String, q: QValue = QValue.One, subTags: List[String] = Nil) extends Renderable with Product with Serializable
- final case class MalformedMessageBodyFailure(details: String, cause: Option[Throwable] = None) extends RuntimeException with MessageBodyFailure with Product with Serializable
Indicates an syntactic error decoding the body of an HTTP Message.
- trait Media[F[_]] extends AnyRef
- sealed class MediaRange extends AnyRef
- sealed class MediaType extends MediaRange
- final case class MediaTypeMismatch(messageType: MediaType, expected: Set[MediaRange]) extends UnsupportedMediaTypeFailure with Product with Serializable
Indicates that no EntityDecoder matches the MediaType of the Message being decoded
- final case class MediaTypeMissing(expected: Set[MediaRange]) extends UnsupportedMediaTypeFailure with Product with Serializable
Indicates that a Message attempting to be decoded has no MediaType and no EntityDecoder was lenient enough to accept it.
- sealed trait Message[F[_]] extends Media[F]
Represents a HTTP Message.
Represents a HTTP Message. The interesting subclasses are Request and Response.
- trait MessageBodyFailure extends RuntimeException with DecodeFailure
Indicates a problem decoding a Message body.
- trait MessageFailure extends RuntimeException
Indicates a failure to handle an HTTP Message.
- final class Method extends Renderable with Serializable
An HTTP method.
An HTTP method.
- final case class ParseFailure(sanitized: String, details: String) extends RuntimeException with MessageFailure with NoStackTrace with Product with Serializable
Indicates an error parsing an HTTP Message.
Indicates an error parsing an HTTP Message.
- sanitized
May safely be displayed to a client to describe an error condition. Should not echo any part of a Request.
- details
Contains any relevant details omitted from the sanitized version of the error. This may freely echo a Request.
- type ParseResult[+A] = Either[ParseFailure, A]
- final case class ProductComment(value: String) extends ProductIdOrComment with Product with Serializable
- final case class ProductId(value: String, version: Option[String] = None) extends ProductIdOrComment with Product with Serializable
- sealed trait ProductIdOrComment extends Renderable
- final case class Protocol(name: CIString, version: Option[CIString]) extends Product with Serializable
- final class QValue extends AnyVal with Ordered[QValue]
A Quality Value.
A Quality Value. Represented as thousandths for an exact representation rounded to three decimal places.
- trait QValuePlatform extends AnyRef
- final class Query extends QueryOps with Renderable
Collection representation of a query string
Collection representation of a query string
It is a indexed sequence of key and maybe a value pairs which maps precisely to a query string, modulo percent-encoding.
When rendered, the resulting
String
will have the pairs separated by '&' while the key is separated from the value with '=' - trait QueryOps extends AnyRef
- trait QueryParam[T] extends QueryParamKeyLike[T]
type class defining the key of a query parameter Usually used in conjunction with QueryParamEncoder and QueryParamDecoder
type class defining the key of a query parameter Usually used in conjunction with QueryParamEncoder and QueryParamDecoder
Any QueryParam instance is also a valid QueryParamKeyLike instance where the same key is used for all values.
- trait QueryParamCodec[T] extends QueryParamEncoder[T] with QueryParamDecoder[T]
- trait QueryParamDecoder[T] extends AnyRef
Type class defining how to decode a QueryParameterValue into a
T
Type class defining how to decode a QueryParameterValue into a
T
- See also
QueryParamCodecLaws
- trait QueryParamEncoder[T] extends AnyRef
Type class defining how to encode a
T
as a QueryParameterValuesType class defining how to encode a
T
as a QueryParameterValues- See also
QueryParamCodecLaws
- trait QueryParamKeyLike[T] extends AnyRef
- final case class QueryParameterKey(value: String) extends AnyVal with Product with Serializable
- final case class QueryParameterValue(value: String) extends AnyVal with Product with Serializable
- final case class RangeUnit(value: String) extends Renderable with Product with Serializable
- final class Request[F[_]] extends Message[F] with Product with Serializable
Representation of an incoming HTTP message
Representation of an incoming HTTP message
A Request encapsulates the entirety of the incoming HTTP request including the status line, headers, and a possible request body.
- final case class RequestCookie(name: String, content: String) extends Renderable with Product with Serializable
- sealed abstract class RequestPrelude extends Product with Serializable
A projection of a Request without the body.
A projection of a Request without the body.
- Note
The Request#attributes are omitted in this encoding because they do not (and can not) have a cats.kernel.Order instance. If they were included here, then we could not write a cats.kernel.Order instance for RequestPrelude, limiting some of its utility, e.g. it could not be used in a cats.data.NonEmptySet.
- final class Response[F[_]] extends Message[F] with Product with Serializable
Representation of the HTTP response to send back to the client
- final case class ResponseCookie(name: String, content: String, expires: Option[HttpDate] = None, maxAge: Option[Long] = None, domain: Option[String] = None, path: Option[String] = None, sameSite: Option[SameSite] = None, secure: Boolean = false, httpOnly: Boolean = false, extension: Option[String] = None) extends Renderable with Product with Serializable
- extension
The extension attributes of the cookie. If there is more than one, they are joined by semi-colon, which must not appear in an attribute value.
- sealed abstract class ResponsePrelude extends Product with Serializable
A projection of a Response without the body.
A projection of a Response without the body.
- Note
The Response#attributes are omitted in this encoding because they do not (and can not) have a cats.kernel.Order instance. If they were included here, then we could not write a cats.kernel.Order instance for ResponsePrelude, limiting some of its utility, e.g. it could not be used in a cats.data.NonEmptySet.
- sealed trait SameSite extends Renderable
RFC6265 SameSite cookie attribute values.
- final case class ServerSentEvent(data: Option[String] = None, eventType: Option[String] = None, id: Option[EventId] = None, retry: Option[FiniteDuration] = None, comment: Option[String] = None) extends Renderable with Product with Serializable
- final case class ServerSoftware(product: String, productVersion: Option[String] = None, comment: Option[String] = None) extends Product with Serializable
- sealed abstract case class Status extends Ordered[Status] with Renderable with Product with Serializable
Representation of the HTTP response code and reason
Representation of the HTTP response code and reason
Note: the reason is not important to the protocol and is not considered in equality checks.
- class TransferCoding extends Ordered[TransferCoding] with Renderable
- sealed abstract class UnsupportedMediaTypeFailure extends RuntimeException with DecodeFailure with NoStackTrace
- final case class Uri(scheme: Option[Scheme] = None, authority: Option[Authority] = None, path: Path = Uri.Path.empty, query: Query = Query.empty, fragment: Option[Fragment] = None) extends QueryOps with Renderable with Product with Serializable
Representation of the Request URI
Representation of the Request URI
- scheme
optional Uri Scheme. eg, http, https
- authority
optional Uri Authority. eg, localhost:8080, www.foo.bar
- path
url-encoded string representation of the path component of the Uri.
- query
optional Query. url-encoded.
- fragment
optional Uri Fragment. url-encoded.
- trait UriPlatform extends AnyRef
- final case class UriTemplate(scheme: Option[Scheme] = None, authority: Option[Authority] = None, path: Path = Nil, query: UriTemplate.Query = Nil, fragment: Fragment = Nil) extends Product with Serializable
Simple representation of a URI Template that can be rendered as RFC6570 conform string.
Simple representation of a URI Template that can be rendered as RFC6570 conform string.
This model reflects only a subset of RFC6570.
Level 1 and Level 2 are completely modeled and Level 3 features are limited to:
- Path segments, slash-prefixed
- Form-style query, ampersand-separated
- Fragment expansion
- final class UrlForm extends AnyVal
Deprecated Type Members
- trait MediaTypePlaform extends AnyRef
- Annotations
- @deprecated
- Deprecated
(Since version 0.22.2) Misspelled, never documented, never mixed into MediaType companion, and obsolete
- final class RequestCookieJar extends AnyVal
- Annotations
- @deprecated
- Deprecated
(Since version 0.21.20) Use the CookieJar middleware instead
Value Members
- val ApiVersion: Http4sVersion
- val EmptyBody: EntityBody[Nothing]
- object AuthScheme
- object AuthedRequest
- object AuthedRoutes
- object BasicCredentials extends Serializable
- case object BuildInfo extends Product with Serializable
This object was generated by sbt-buildinfo.
- object CacheDirective
A registry of cache-directives, as listed in http://www.iana.org/assignments/http-cache-directives/http-cache-directives.xhtml
- object Charset extends CharsetCompanionPlatform with Serializable
- object CharsetRange
- object ContentCoding
- object ContextRequest extends Serializable
- object ContextResponse extends Serializable
- object ContextRoutes
- object Credentials
- object DecodeFailure extends Serializable
- object DecodeResult
- object Entity extends Serializable
- object EntityDecoder
EntityDecoder is used to attempt to decode an EntityBody This companion object provides a way to create
new EntityDecoder
s along with some commonly used instances which can be resolved implicitly. - object EntityEncoder
- object EntityTag extends Serializable
- object FormDataDecoder
- object Header
- object Headers
- object Http
Functions for creating Http kleislis.
- object HttpApp
Functions for creating HttpApp kleislis.
- object HttpCodec
- object HttpDate
- object HttpRoutes
Functions for creating HttpRoutes kleislis.
- object HttpVersion extends Serializable
- object LanguageTag extends Serializable
- object LiteralSyntaxMacros
- object Media
- object MediaRange
- object MediaType extends MimeDB
- object Message
- object Method extends Serializable
- object ParseFailure extends Serializable
- object ParseResult
- object ProductComment extends Serializable
- object ProductId extends Serializable
- object ProductIdOrComment
- object Protocol extends Serializable
- object QValue extends QValuePlatform
- object QValuePlatform
- object Query
- object QueryParam
- object QueryParamCodec
- object QueryParamDecoder
- object QueryParamEncoder
- object QueryParamKeyLike
- object QueryParameterKey extends Serializable
- object QueryParameterValue extends Serializable
- object RangeUnit extends Serializable
- object Request extends Serializable
- object RequestCookie extends Serializable
- object RequestPrelude extends Serializable
- object Response extends KleisliSyntax with Serializable
- object ResponseCookie extends Serializable
- object ResponsePrelude extends Serializable
- object SameSite
- object ServerSentEvent extends Serializable
- object ServerSoftware extends Serializable
- object StaticFile
- object Status extends Serializable
- object TransferCoding
- object Uri extends UriPlatform with Serializable
- object UriPlatform
- object UriTemplate extends Serializable
- object UrlForm
- object implicits extends AllSyntax
Deprecated Value Members
- val DefaultCharset: Charset
- Annotations
- @deprecated
- Deprecated
(Since version 0.22.8) Use Charset.
UTF-8
directly
- object MediaTypePlaform
- Annotations
- @deprecated
- Deprecated
(Since version 0.22.2) Misspelled, never documented, and obsolete
- object RequestCookieJar
- Annotations
- @deprecated
- Deprecated
(Since version 0.21.20) Use the CookieJar middleware instead