http = option.rest
// Posting a message that we got through 1Gateway through REST
json = message.toJson()
url = "https://postman-echo.com/post"
// set content type and accept headers
http.content("application/json")
http.accept("application/json")
// set authentication from credential store if needed
// http.useAuth("1gtw_creds")
// gets the configuration of the authentication from API
authConfig = api.getAuth("1gtw_creds")
// gets the authentication from the authentication configuration
auth = authConfig.getAuthentication()
// println authConfig.class.superclass.name
// println auth.class
// set the authentication on the HTTP request
http.setAuth(auth)
// add the authentication username as header
http.addHeader("Username", auth.user)
// POST the message with headers and authentication
res = http.post(url, json)
// Retrive the response from the last request
res2 = http.getResponse()
// get status code from the last request
statuscode = http.statuscode
// check that both responses are the same
assert res.equals(res2)
// println res
println statuscode
println http.getStatuscode()
// get reason from the last request
println http.getReason()
// get response headers from the last request in a map
println http.getResponseHeaders()
// to retrieve one of the response headers, call get with the name of the header
http.getResponseHeaders().get("Content-Type")
println http.getProxy()
res = http.put("https://postman-echo.com/put", json)
println res
res = http.patch("https://postman-echo.com/patch", json)
println res
res = http.delete("https://postman-echo.com/delete")
println res
res = http.gc()
println res
http.ok(404)
res = http.get("https://postman-echo.com/status/404")
println res
println http.getReason()
println http.getException()
println http.getResponseHeaders()
http.invalid(200)
try {
res = http.get("https://postman-echo.com/status/200")
} catch (Exception e){
println e
println http.getReason()
println http.getException()
println http.getResponseHeaders()
}
http.trans(200)
try {
res = http.get("https://postman-echo.com/status/200")
} catch (Exception e){
println e
println http.getReason()
println http.getException()
println http.getResponseHeaders()
}
http.fatal(200)
try {
res = http.get("https://postman-echo.com/status/200")
} catch (Exception e){
println e
println http.getReason()
println http.getException()
println http.getResponseHeaders()
}