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?Section titled 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
PreviewProviderfunction, 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 BuilderSection titled 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
JSONas the response, if the request is a
POST, by altering the
content-typeheader and returning the object using the
In case the request is a
GET, and you wish to return an HTML page, the
content-typeshould be set as
text/html:charset=UTF-8. The response is going to be presented already rendered on the preview.
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 ChatGPTSection titled 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.
ImplementationSection titled Implementation
Here’s a real-life implementation of the Edge Functions ChatGPT integration:
|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|