Tip of the Day
When using the RESTinstance library, it is incredibly easy to do basic authentication login.Todays example will demonstrate how to login to a RESTful API service without passing in any added headers (if you want an example of that, let me know), but will use the json schema to validate the returned response from your POST call.
Test Example
*** Test Cases ***
POST Login Valid User
Expect Response ${CURDIR}/schemas/valid/basic_auth_schema.json
POST /api/login body={"email":"ex@g.com","password":"example"}
Usually, you would want to test the status code after your `POST` by using the `Integer` call, but by calling `Expect Response` and using the schema, you can have all of your status code and required response fields all in one!JSON Schema
{
"body":{
"type":"object",
"properties":{
"token":{
"type":"string"
}
},
"required":[
"token"
]
},
"status":{
"type":"integer",
"example":200,
"enum":[
200
]
}
}
When a `POST` call is made, the schema is asserting that the status code should return a 200 response code, and the token should be returned as a string.And that's all there is to it! Easy right? Good luck!
You can download a fully working example and more!
Download on github.
RESTinstance - RESTful Basic Authentication
Reviewed by JJ The Engineer
on
11:45 AM
Rating:
No comments: