tencent cloud


Returning a JSON Object

Last updated: 2024-01-25 14:26:56
    In this example, an edge function is used to generate a JSON object, and the JSON object is accessed and previewed from a browser.

    Sample Code

    const data = {
    content: 'hello world',
    async function handleRequest(request) {
    // Convert the JSON object to the String format.
    const result = JSON.stringify(data, null, 2);
    return new Response(result, {
    headers: {
    'content-type': 'application/json; charset=UTF-8',
    addEventListener('fetch', event => {
    return event.respondWith(handleRequest(event.request));

    Sample Preview

    In the address bar of the browser, enter a URL that matches a trigger rule of the edge function to preview the effect of the sample code.


    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support