ConnectorTypeREST
class connector_types.connector_type_rest.ConnectorTypeREST
Call a REST service.
Input Schema
-
urlThe URL to connect to.
Use the format <scheme>://<hostname>/<path>.
Either
urlorhostnamemust be set. When both are specified,urltakes precedence.Type:
anyOfOptions: -
schemeThe scheme to use.
Type:
anyOfOptions: -
hostnameThe host to connect to.
Either
urlorhostnamemust be set. When both are specified,urltakes precedence.Type:
anyOfOptions: -
portThe port to connect to.
Defaults to 443 when using the "https"
scheme, defaults to 80 when using the "http"scheme.Type:
anyOfOptions: -
base_pathA part of the path. The full path will be
<base path>/<path>.Type:
anyOfOptions: -
pathA part of the path. The full path will be
<base path>/<path>.Type:
anyOfOptions: -
methodThe HTTP method to use.
Type:
anyOfOptions: -
paramsWill be urlencoded automatically
Type:
objectAdditional Properties:
TruePattern Properties:
-
.*Value of the parameter
-
-
bodyA body payload to send with the request. Only allowed for the methods
post,put,patch, anddelete.Type:
anyOfOptions: -
textDEPRECATED. Replaced by
body.text. -
jsonDEPRECATED. Replaced by
body.json. -
multipartDEPRECATED. Replaced by
body.multipart. -
urlencodedDEPRECATED. Replaced by
body.urlencoded. -
headersHeaders to send with the request.
Type:
anyOfOptions:Default:
Header list -
cookiesCookies to send with the request.
Type:
objectAdditional Properties:
TruePattern Properties:
-
.*Type:
string
-
-
cacertUse a self-signed certificate to verify the https connection. To disable certificate verification set
verify_ssltoFalse.Type:
anyOfOptions: -
verify_sslPerform validation of ssl certificates. This can be disabled to use self-signed certificates where the CA certificate is not available.
Type:
booleanDefault:
True -
expected_status_codeHTTP status codes which result in ENDED_SUCCESS. All other HTTP status codes will result in ENDED_ERROR.
Type:
arrayItems:Default:
[200, 201, 202, 204] -
allow_redirectsIf set to
Falsedo not follow redirects.Trueby default.Type:
booleanDefault:
True -
max_redirectsMaximum number of redirects to follow.
10by default.Type:
integerDefault:
10 -
total_timeoutTotal timeout in seconds for the whole request. Can be disabled by setting to
0.Type:
integer -
connect_timeoutA timeout in seconds for connecting to a peer. Can be disabled by setting to
0.Type:
integer -
read_timeoutA timeout in seconds for reading a portion of data from a peer. Can be disabled by setting to
0.Type:
integer -
authenticationType:
anyOfOptions: -
dstWhere to store the response.
Type:
anyOfOptions: -
dataDEPRECATED. Replaced by
body.json. -
retry_status_codeDEPRECATED. Not used. Use the
retrywrapper instead. -
retry_backoffDEPRECATED. Not used. Use the
retrywrapper instead. -
authentication_methodDEPRECATED. Replaced by
authentication.authentication_method_name. -
usernameDEPRECATED. Replaced by
authentication.username. -
passwordDEPRECATED. Replaced by
authentication.password. -
grantDEPRECATED. Replaced by
authentication.grant.
Output Schema
-
status_codeThe status code of the HTTP response.
Type:
integer -
headersThe headers of the HTTP response.
Type:
anyOfOptions:Default:
Header list -
cookiesCookies which were retrieved with the HTTP response.
Type:
objectAdditional Properties:
TruePattern Properties:
-
.*Type:
objectProperties:Additional Properties:
False
-
-
encodingThe encoding used in the HTTP response.
Type:
string -
bytesThe base64 encoded binary response body. Will only be set if the body cannot be represented as text or json.
Type:
string -
textThe response body. Will only be set if it can be represented as text, but it cannot be represented as json.
Type:
string -
jsonThe response body. Will only be set if it can be represented as text and json.
-
historyThe history of all requests made when
allow_redirectsis set.Type:
arrayItems:
Constants
ssl_context_inputs = ['check_hostname', 'client_cert', 'client_key', 'server_ca']Example
import flow_api
def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
# create a REST connection and run it
child_execution = this.connect(
connector_type='REST',
url='https://api.chucknorris.io/jokes/random',
)
# access a field of the JSON response
joke = child_execution.get('output_value')['json']['value']
# end with a joke
return this.success(message=joke)
More
Specify parts of URL
Alternatively to specifying the full URL it is possible to specify different parts of the URL separately:
import flow_api
def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
# the resulting URL will be
# https://httpbin.org/anything/some/path?query=parameter
this.connect(
connector_type='REST',
scheme='https', # defaults to https
hostname='httpbin.org',
base_path='anything',
path='some/path',
params={
'query': 'parameter',
},
)
return this.success('all done')
Sending multipart POST requests
The Cloudomation Engine REST connector can be used to upload files using a multipart POST request. Here are some usage examples:
Basic example
Specify a value in the part for a string payload, or specify a file in the
part to upload a file from the Cloudomation Engine files resource.
this.connect(
connector_type='REST',
url='https://httpbin.org/post',
method='POST',
multipart={
'parts': [
{
'name': 'string-field',
'value': 'spam & eggs',
},
{
'name': 'file',
'file': 'report.txt',
},
],
},
)
The example above will generate the following request:
Content-Length: '991'
Content-Type: multipart/mixed; boundary=aec30e9afc384303b6cb67e44aaa0f9c
--aec30e9afc384303b6cb67e44aaa0f9c
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name="string-field"
Content-Length: 11
spam & eggs
--aec30e9afc384303b6cb67e44aaa0f9c
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name="file"; filename="report.txt"
Content-Length: 608
...content of the report.txt file...
--aec30e9afc384303b6cb67e44aaa0f9c--
Full example
It is possible to modifiy the request being generated.
- Specify a custom
content-typeorboundaryin the multipart dictionary to override the default values. - Specify a custom
content-type,content-disposition, orcontent-lengthin the part dictionary to override the default values. - Specify
Falseforcontent-type,content-disposition, orcontent-lengthin the part dictionary to omit the field in the request.
this.connect(
connector_type='REST',
url='https://httpbin.org/post',
method='POST',
multipart={
'content-type': 'application/my-custom-content-type',
'boundary': 'my-custom-boundary',
'parts': [
{
'name': 'string-field',
'value': '<pre>spam & eggs</pre>',
'content-type': 'text/html',
'content-disposition': False,
'content-length': False,
},
{
'name': 'file',
'file': 'report.txt',
'content-disposition': 'form-data; filename="report.txt"',
},
],
},
)
The example above will generate the following request:
Content-Length: '848'
Content-Type: application/my-custom-content-type; boundary=my-custom-boundary
--my-custom-boundary
Content-Type: text/html
<pre>spam & eggs</pre>
--my-custom-boundary
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; filename=\"report.txt\"
Content-Length: 608
...content of the report.txt file...
--my-custom-boundary--