Azion Preview Deployment
Azion Preview Deployment makes it possible for you to preview the behavior of your edge functions before they go to production. New possibilities are unlocked when using the Preview, such as:
- Test different flows based on the http method provided.
- See the outcome of an HTML page.
- Return data in JSON.
How does Azion Preview Deployment work?
Azion Preview Deployment depends on an auxiliary function inside your source code. This function is called PreviewProvider
, and it’s responsible for debugging and simulating a request, returning the outcome to be rendered. The PreviewProvider
function is represented as:
Note: without the
PreviewProvider
function, it isn’t possible to visualize the preview.
Now, with your simulated request running, you’re able to set different behaviors to your function, based on all properties available inside the request variable, such as:
In this code snippet, it’s defined that if a GET
request is called, it returns the HTML
var, containing the html to be output, and set its content type as required to perform this action.
API Builder
It’s also possible to build APIs and have the outcome based on the request method. For example:
-
You can have an object in
JSON
as the response, if the request is aPOST
, by altering thecontent-type
header and returning the object using theJSON.stringify()
function. -
In case the request is a
GET
, and you wish to return an HTML page, thecontent-type
should be set astext/html:charset=UTF-8
. The response is going to be presented already rendered on the preview.
Example:
The output is shown right next to the code editor. It’s possible to open it on a different tab as well, clicking on the open button.
Preview Provider and ChatGPT
The ChatGPT integration helps you to boost your productivity and, alongside the Preview Deployment, enables more analytical implementations, making it possible to test and see new ideas on the fly. Take a look at Edge Functions Chat GPT integration.
Implementation
Here’s a real-life implementation of the Edge Functions ChatGPT integration:
Implementation | Description |
---|---|
How to build an API with Edge Functions and ChatGPT | See how to build an API and have its responses returned in JSON, with the help of ChatGPT |