0.0.5 • Published 12 months ago

remix-endpoint v0.0.5

Weekly downloads
-
License
-
Repository
-
Last release
12 months ago

Remix Endpoint

Inpsired by Koa Zod Router. Create Remix endpoints (both loaders and actions) with

Installation

pnpm install remix-endpoint

Usage

import { RemixAction, Router } from "remix-endpoint";
import { createIntent } from "remix-endpoint/react/createIntent";
import { zfd } from "zod-form-data";
import { z } from "zod";

enum ActionIntent {
  CREATE_OBJECT = "createObject"
}

// alternatively, just import from react/Intent (but this only uses strings)
const Intent = createIntent<ActionIntent>();

export const action = new RemixAction()
  .register({
    method: "POST",
    intent: ActionIntent.CREATE_OBJECT,
    validate: {
      // if you wanted to validate body instead:
      // body: z.object({ name: z.string() })

      // but remix forms are better:
      formData: zfd.formData({
        name: z.text(),
      }),
    },
    handler: async ({ formData: { name } }) => {
      await createObject(name);
      return Router.standardResponse(true, "Successfully created object!");
    },
  })
  .create();


<Form>
  <Intent value={ActionIntent.CREATE_OBJECT}>
</Form>
0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago