DreamFactory includes a web-based administration console used for performing tasks such as managing APIs, administrators, and business logic. However many users prefer to instead automate administrative tasks through scripting. This is useful for several reasons. First, automation reduces the amount of work required to manage multiple DreamFactory environments. Second, it opens up the possibility of integrating DreamFactory features into third-party applications such as an API monetization SaaS. In this post we’ll demonstrate just how easy managing your DreamFactory instance using the system APIs can really be.
Scripting Creation of a Database API
To interact with DreamFactory’s system API you’ll first create a role and associated API key capable of interacting with the API. If you don’t already know how to do this please refer to the sections of the “Getting Started with DreamFactory” guide titled “Creating a Role” and “Creating an Application”. With that done, open up your HTTP testing client (we are partial to Insomnia but Postman works equally well). Create a POST request to the URI /api/v2/system/service and add the following request payload:
Be sure to update the HOSTNAME, DATABASE, USERNAME, and PASSWORD placeholders to reflect the credentials associated with your MySQL database. Of course, you’re not limited to creating just MySQL APIs; any of DreamFactory’s supported service types can be created and managed using the system APIs. After submitting a successful request, a 201 Created status code is returned along with the newly created service’s ID:
We invite you to check out the latest chapter in our guide, creatively titled “Using the System APIs” for more examples like this, including a Bash shell scripting example which could serve as the starting point for automating management of a multi-environment DreamFactory solution.