Build a Microservice (Python)
WayScript allows you to configure your Lair to build an serverless API endpoint in minutes.
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.from wayscript import context
from wayscript.triggers import http_trigger
# Get payload for request event
request_payload = context.get_event()
# Parse header and request body from request payload
request_header = request_payload['data'].get('headers')
request_body = request_payload['data'].get('data')
# Specify response payload
response_payload = {"hello": "world"}
response_headers = {"content-type": "application/json"}
status_code = 200
# Send response
http_trigger.send_response(data=response_payload, headers=response_headers, status_code=status_code)
Open your Lair’s Triggers Panel and add a new
http
trigger. Create a name for your trigger and input the following run command. See Triggers for more details.python api.py
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).
Navigate to the
*.wayscript.cloud
endpoint generated by your http
trigger to see your simple API in action!
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.By default, your Lair's endpoints are protected against unauthenticated requests. See Endpoints on how to public expose your endpoints or authenticate using your application key.