# next-json-api

> Dead simple helper function to send json response in nextjs api routes

Latest version **2.2.0** (published 2023-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install next-json-api
pnpm add next-json-api
yarn add next-json-api
bun add next-json-api
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2023-04-30 |
| First published | 2023-02-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 51 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nick Wylynko |
| Maintainers | nwylynko |
| Keywords | next, api, json |

## Links

- npm: https://www.npmjs.com/package/next-json-api
- Repository: https://github.com/nwylynko/next-json-api
- Homepage: https://github.com/nwylynko/next-json-api#readme
- Issues: https://github.com/nwylynko/next-json-api/issues
- npm.io page: https://npm.io/package/next-json-api

## Dependencies (1)

- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.21

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.2.0 (latest) — 2023-04-30
- 2.1.0 — 2023-04-10
- 2.0.1 — 2023-02-14
- 2.0.0 — 2023-02-14
- 1.4.0 — 2023-02-14
- 1.3.0 — 2023-02-09
- 1.2.0 — 2023-02-09
- 1.1.2 — 2023-02-09
- 1.1.1 — 2023-02-09
- 1.1.0 — 2023-02-09
- 1.0.2 — 2023-02-09
- 1.0.1 — 2023-02-09
- 1.0.0 — 2023-02-09

## README

# next-json-api
small function to simplify nextjs api routes

```ts
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>>;
```

---
_Source: https://npm.io/package/next-json-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
