Export page content using http functions

146 Views Asked by At

I was trying to follow the example found here:

https://support.wix.com/en/article/corvid-exposing-a-site-api-with-http-functions

To expose something on my site using HTTP get, but I don't understand how to define a function like seen on their example page.

They have: get_apartmentlistings() but where is apartmentlistings and how do I define something similar?

This is my page: https://cesarcaiooliveira.wixsite.com/cesar/page

And I'm trying to read the text content, and this is what I already did:

import { ok, notFound, serverError } from 'wix-http-functions';
import wixData from 'wix-data';

export function get_textlist() {
  let options = {
    "headers": {
      "Content-Type": "application/json"
    }
  };
  return wixData.query("textlist")
  .find()
  .then(results => {
    if (results.items.length > 0) {
      options.body ={
        "items": results.items
      }
      return ok(options);
    }
  })

}

enter image description here

export function get_textlist()

My doubt is here ^ how do i link it to my text content?

1

There are 1 best solutions below

0
On

HTTP functions are backend code. They do not have direct access to the elements on a page. This makes sense because when an HTTP function is called by a consumer of your API the consumer is not on a page of your site.

It's hard to tell exactly what you want to do here, but maybe you'd be better off storing the info you want to expose in a database collection instead of on a page. You can query the database collection to return the data in the HTTP function.