Introduction
WayScript makes it really easy to make a fully fleshed out APIs in minutes. Today we'll be be discussing how to make a GET API.
Prerequisites
In order to make the API, we'll utilize an HTTP Trigger, a SQL Module, a Python Module, and an HTTP Response. There are no prerequisites but some content you might find helpful:
Working with HTTP
Working with Python
Working with SQL
Building the GET API
With WayScript, you can set up a workflow really quickly.
You can create a workflow by clicking the + New Script
Button in the top right corner of the website.
In this Script, to make a workflow he using the HTTP Trigger module, which will make a request to our database any time we hit a valid endpoint. Modules are sort of like building blocks, to help form the foundation of our application. After adding the HTTP Trigger Module to the workflow, click on the module and go to the window in the left to add endpoints and query paramters for your API.
After adding the query parameters we can get going with connecting to our SQL database and using the query parameters from our HTTP Trigger.
First, click the SQL Module. WayScript allows you to sink up with a MySQL, PostgresSQL, or SQL Server DB and is adding new ones all the time.
After you put in your DB info you. You can query it and alter the qurey so that you can use one of the parameters from your HTTP Trigger.
Now we can query the database to get the entry that we want! Make sure to set up indexes at the columns you would like to use.
Next you need to take the information from your Database response and turn it into a JSON response with the Python Module.
Click on the Python Module and create a JSON response and put it in your dictionary as resp so you can reference it later.
WayScript type checks your dictionary variables so they make it really easy to know if you formatted your response correctly.
After you add your response to your HTTP Response module and turn on the HTTP Trigger you're good to go!
Result
If you call or go to the endpoint at the supplied query parameters you can see your response!
If you would like to see this example app check out this script with GET and POST requests, it is public on the WayScript market place. Also feel free to check out other scripts on the WayScript Market Place.
Here's a great video of Erik Toor building this Script.
Top comments (0)