Build an API
WayScript X allows you to configure your Lair to build an API endpoint in minutes.

Create api.py

Use the boilerplate code below to create an api.py file in your Lair’s root directory. See File system for more details on how to manipulate files in your workspace file system.

Boilerplate api.py

1
# my-lair-a > api.py
2
3
from wayscript.triggers import http_trigger
4
5
payload = {"hello": "world"}
6
headers = {"content-type": "application/json"}
7
status_code = 200
8
9
http_trigger.send_response(data=payload, headers=headers, status_code=status_code)
Copied!

Configure http trigger

Open your Lair’s .triggers file and add a new http trigger. Create a name for your trigger and input the following run command. See Triggers for more details.
1
$ python api.py
Copied!
If you are using the WayScript X desktop app, you must press "Push" to sync your new and modified files to remote (see File system or more details).

Test your API in development environment

Navigate to the *.wayscript.cloud endpoint generated by your http trigger to see your simple API in action!

Deploy to production environment

Once you have finished testing, press “Deploy” to create a production environment for your API. Select <Lair_name>.prod in the Lair selector menu and view the http trigger to access your API’s production endpoint. See Hosted environments for more details.
Last modified 1mo ago