HTTP ConstantsΒΆ
sttp provides constants for common HTTP header names, media types, and status codes.
Constants for common header names are provided by the HeaderNames
trait and object.
Constants for common media types are provided by the MediaTypes
trait and object.
Constants for common status codes are provided by the StatusCodes
trait and object.
Example with objects:
import com.softwaremill.sttp._
object Example {
val request = sttp.header(HeaderNames.ContentType, MediaTypes.Json).get(uri"https://httpbin.org")
implicit val backend = HttpURLConnectionBackend()
val response = request.send()
if (response.code == StatusCodes.Ok) println("Ok!")
}
Example with traits:
import com.softwaremill.sttp._
object Example extends HeaderNames with MediaTypes with StatusCodes {
val request = sttp.header(ContentType, Json).get(uri"https://httpbin.org")
implicit val backend = HttpURLConnectionBackend()
val response = request.send()
if (response.code == Ok) println("Ok!")
}