How can I use Cloudflare Pages as an API server like Cloudflare Workers?

I’m currently using Cloudflare Workers as an API endpoint to return data to my application when I call the Worker URL. I’d like to achieve the same functionality using Cloudflare Pages. How can I configure Cloudflare Pages to return JSON data to my application instead of displaying web pages?
Any guidance on how to set up Cloudflare Pages to function as an API server would be greatly appreciated.