2.2.0 • Published 1 year ago

next-json-api v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

next-json-api

small function to simplify nextjs api routes

import { JsonHandler, ApiError } from "next-json-api";

// wrap your handler in JsonHandler
const handler = JsonHandler(async (req, res) => {
  if (Math.random() > 0.5) {

    // throw ApiError with the status code and message
    throw new ApiError(500, "Something went wrong");
  }

  // return the response
  return {
    hello: "world",
  };
});

export default handler;

// import this client side to get the same type
export type Response = Awaited<ReturnType<typeof handler>>;
2.2.0

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago