Start with a simple query and move up from there
import {response} from 'wix-http-functions';
import wixData from 'wix-data';
// You need to suppress authorization if your database has permissions
let full_suppress = {
"suppressAuth": true,
"suppressHooks": true
};
export function get_filter(request) {
// First check if a query parameter is present in the request or not
if(request.query) {
return wixData.query("contact01") //remember to put a return here
.find(full_suppress) //suppress authorization checks
.then( (res) => {
// Now check the length of the items retrieved
if(res.items.length > 0) {
// Items found so return a 200 HTTP response
let options = {
status: 200,
body: res.items
};
return response(options); // similar to ok()
} else {
// No items found, return a 404 HTTP response
let options = {
status: 404,
body: 'No items found'
};
return response(options); // similar to notFound()
}
})
.catch( (error) => {
// This will catch any error with the wixdata query
let options = {
status: 500,
body: error
};
return response(options); // similar to serverError()
});
} else {
// Send a 400 response if no query params are found
let options = {
status: 400,
body: 'No query parameters found'
};
return response(options); // similar to badRequest()
}
}
Read my comments, this is a basic scenario on how to create a http function and get database items using an api call