other-emerald
other-emerald•2mo ago

I want to create a single custom POST route in my app!

Currently using supabase as data source provider I'm unable to find documentation for it! I'm using react router and I tried action or followed react-router docs to create post request but it isn't working, can somebody tell me how can I create a custom POST api endpoint!? I will be grateful 🙂
3 Replies
kapa.ai
kapa.ai•2mo ago
Hi @DOPΣ. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In refine, the create action represents a POST request sent to the database. This is done with the dataProvider.create() method that the @refinedev/supabase package provides. To create a custom POST route, you can use the create action in a component. For example, in the CreateCanvas component, you can use the useModalForm hook from @refinedev/antd to create a form inside a modal. The resource and action properties of the hook should be set to the name of the table in the Supabase database and "create", respectively. Here is an example of how you can use the useModalForm hook to create a form for a POST request:
const { modalProps, formProps, show } = useModalForm<Canvas>({
resource: "canvases",
action: "create",
redirect: "show",
});
const { modalProps, formProps, show } = useModalForm<Canvas>({
resource: "canvases",
action: "create",
redirect: "show",
});
In this example, Canvas is the type of the data that will be sent in the POST request. The resource property is set to "canvases", which is the name of the table in the Supabase database. The action property is set to "create", which represents a POST request. The redirect property is set to "show", which means that after the POST request is successful, the user will be redirected to the "show" page of the created canvas. You can then use the formProps to create the form fields and the modalProps to control the visibility of the modal. The show function can be used to open the modal when the user clicks on a button. For more information, you can refer to the Adding CRUD Actions and Authentication (https://refine.dev/blog/refine-pixels-3#refine--create-action) section of the refine documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai•2mo ago
<@739454321661313025> kapa.ai is still learning and improving, please let us know how it did by reacting below
other-emerald
other-emerald•2mo ago
Can any real human help?