Python calling DreamFactory-mounted APIs

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsPython calling DreamFactory-mounted APIs
 
Line 1: Line 1:
 
To seamlessly call DreamFactory-mounted APIs from your Python scripts. You can use the platform's custom data structures to call DreamFactory-hosted APIs like this:  
 
To seamlessly call DreamFactory-mounted APIs from your Python scripts. You can use the platform's custom data structures to call DreamFactory-hosted APIs like this:  
  
<code>api = platform['api']
+
<source lang="python">
 +
api = platform['api']
  
 
url = 'mysql/api/v2/employees?limit=5'
 
url = 'mysql/api/v2/employees?limit=5'
  
result = api.get(url)</code>
+
result = api.get(url)
 +
</source>
  
 +
This result variable is a Python httplib.HTTPResponse instance. So it would be useful to know what HTTP status code is being returned. You can print it to the log using this statement:
 +
<source lang="python">
 
print result.status
 
print result.status
 +
</source>

Latest revision as of 19:16, 12 March 2019

To seamlessly call DreamFactory-mounted APIs from your Python scripts. You can use the platform's custom data structures to call DreamFactory-hosted APIs like this:

api = platform['api']
 
url = 'mysql/api/v2/employees?limit=5'
 
result = api.get(url)

This result variable is a Python httplib.HTTPResponse instance. So it would be useful to know what HTTP status code is being returned. You can print it to the log using this statement:

print result.status