playframework - Scala testing Web Service Client for POST request -


so play documentation can find here gives simple example call without auth header or parameters.

could me figure out how use similar strategy more complex post request json data body , auth header required? can't work right now.

i want know how test client using ws it's external http requests.

thanks

here snippet of code 1 of projects sends sms via twilio api:

class smsserviceimpl @inject()(config: configuration, ws: wsclient) extends smsservice {    val twilloaccountsid = config.getstring("twillo.accountsid").get   val twilloauthtoken = config.getstring("twillo.authtoken").get   val smsapiurl = config.getstring("twillo.apibaseurl").get + "/" +twilloaccountsid+"/messages.json"    override def send(phone: string, message: string): future[unit] = {     val data = map(       "to" -> seq(phone),       "from" ->  seq(config.getstring("twillo.fromphone").get),       "body" -> seq(message)     )     val response: future[wsresponse] = ws.url(smsapiurl).withauth(twilloaccountsid, twilloauthtoken, wsauthscheme.basic).post(data)     response.map { response =>       response.status match {         case 201 => unit         case _ => throw new smssendingexception(s"failed send sms. got https status: ${response.status}")       }     }   } 

it post request authentication.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -