So I have an POST API in remix.
How can I validate these field in a middleware? Is there any lib that support this or do I have to write checking in every file for every field in object.
import { json } from "@remix-run/node";
export const action = async ({params, request}) => {
let raw_data = await request.text();
let body = JSON.parse(raw_data)
const customerProfile = JSON.stringify({
session_id: body?.session_id,
first_name: body?.first_name,
last_name: body?.last_name,
phone: body?.phone,
email: body?.email,
})
// Do something here
return json(
{ ...result },
{
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST"
},
}
);
}
The request is from another server not in same server.