Mechanisms for making HEAD, GET, POST, PUT, PATCH and DELETE requests.
To utilise this library add this to your sbt build file
"com.cjww-dev.libs" % "http-verbs_2.11" % "2.4.0"
Contains exceptions to catch errors for the session not containing the correct values as well specific http status code such as, Forbidden, Conflict, NotFound and error ranges.
Utility functions to get session and context id's from a http request header.
Contains utilities that can decrypt the response body into type T if the response code is in the success range.
Contains utilities to fetch Id's and names from the http session.
Can be injected into a class that needs to make calls out to external services.
For all these methods you need an implicit Request[_] in scape.
GET needs an implicit Json Reads[T] in scope.
POST, PUT and PATCH need an implicit Json OWrites[T] in scope.
//HEAD and GET example
case class TestModel(str: String, int: Int)
implicit val reads = Json.reads[TestModel]
class ExampleConnector @Inject()(http: Http) {
def exampleHeadRequest: Future[WSResponse] = {
http.HEAD("/example/url")
}
def exampleGetTestModel: Future[TestModel] = {
http.GET[TestModel]("/example/url")
}
}
//POST, PUT and PATCH example
case class TestModel(str: String, int: Int)
implicit val writes = Json.writes[TestModel]
class ExampleConnector @Inject()(http: Http) {
def examplePost: Future[WSResponse] = {
http.POST[TestModel]("/example/uri", TestModel("abc", 616))
}
def examplePut: Future[WSResponse] = {
http.PUT[TestModel]("/example/uri", TestModel("abc", 616))
}
def examplePatch: Future[WSResponse] = {
http.PATCH[TestModel]("/example/uri", TestModel("abc", 616))
}
}
class ExampleConnector @Inject()(http: Http) {
def exampleDelete: Future[WSResponse] = {
http.DELETE("/example/uri")
}
}
This code is open source software licensed under the Apache 2.0 License