ESC
Tutorials > Regular API Calls
Go to /react-native-starter-backend/functions/src/index.ts file and it is as easy as adding a new function declaration like below to create a publicly accessible API endpoint in React Native Starter AI!
Here is an example public API endpoint for collecting email leads:
/react-native-starter-backend/functions/src/index.ts
1export const publicApiExample = onRequest(async (request, response) => {
2
3 const email = request.body.email;
4
5 if (!email) {
6 response.json({ error: "Email is required" });
7 }
8
9 try {
10 // Do anything with the email input
11
12 response.json({});
13 } catch (e: any) {
14 console.error(e);
15 response.json({ error: e.message });
16 }
17 });