Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remix Examples #46

Closed
moishinetzer opened this issue Sep 4, 2022 · 5 comments
Closed

Remix Examples #46

moishinetzer opened this issue Sep 4, 2022 · 5 comments

Comments

@moishinetzer
Copy link

You say that this can work with any node-based backend. However, it seems the whole implementation is based on next.js request handlers. Could you please provide an example for remix? Thanks!

@ogroppo
Copy link
Contributor

ogroppo commented Sep 4, 2022

Hi @moishinetzer, actually only the examples are in next but it's not really coupled to that... I am not familiar with remix but I am looking at the docs right now, it seems there isn't the concept of response object? (request instead is the first parameter of the API route function).
So I guess the only problem would be the res.json that in Remix is just json... interesting

@moishinetzer
Copy link
Author

Yes exactly, and also the Request has a different type signature for some reason?

@ogroppo
Copy link
Contributor

ogroppo commented Sep 4, 2022

uuuh just saw this in remix docs const body = await request.formData(); - I'm afraid remix have gone down a different route to the point it's not compatible with traditional request/response objects.
Given the low support requests for remix I don't think we are able to accommodate this, will mention in readme, sorry!

@matt-winfield
Copy link

I've been experimenting with this, and it seems to work fine with Remix. You need to expose resource route using a file called api.$.tsx (if using flat routes), and then set your file contents like this:

import { prisma } from '../your/prisma/client.tsx';
import { json, type DataFunctionArgs } from '@remix-run/server-runtime';
import { defaultHandler, type RaPayload } from 'ra-data-simple-prisma';

export const loader = async ({ request }: DataFunctionArgs) => {
    const body = (await request.json()) as RaPayload;

    const result = await defaultHandler(body, prisma);
    return json(result);
};

export const action = loader;

This seems to behave as expected.

@ogroppo
Copy link
Contributor

ogroppo commented Sep 5, 2023

Hi @matt-winfield, indeed - From version 3 it's completely up to the framework to send the response (and to get the body accordingly), so any backend would work really... Thanks for the example tho, I will add it to readme!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants