generated from Decatur-Robotics/npm-package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d3ac7a
commit 0d67af3
Showing
4 changed files
with
896 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
# NPM Package Template | ||
# Next.js for Unified API | ||
|
||
To get started, use this repo as a template and do the following: | ||
Install with `npm i unified-api-nextjs`. | ||
|
||
- Update the details in package.json | ||
- Update the assignees in .github/dependabot.yml | ||
- Add your NPM_TOKEN to the repository secrets (needed to publish to NPM) | ||
- Add your GIT_PUSH_TOKEN to the repository secrets (needed to auto-increment the version number) | ||
Works like the regular [`unified-api`](https://www.npmjs.com/package/unified-api) package, but with types for Next.js. | ||
|
||
Branch protection is set up for the main branch, requiring you to PR into main, have at least one review, and pass CI checks. Creating a PR will also automatically increment the patch number. | ||
In place of `ApiTemplate`, use `NextApiTemplate`. Likewise, use `NextServerApi` in place of `ServerApi`. | ||
|
||
Comes with ESLint, Prettier, and Jest set up. To run tests, use `npm test`. To run linting, use `npm run lint`. To run prettier, use `npm run format`. | ||
To connect Next.js to the API, use the following snippet: | ||
|
||
Commits to main are automatically published to NPM (provided your CI checks pass and you've changed the package name). | ||
```typescript | ||
import ClientApi from "@/lib/api/ClientApi"; // Your ApiTemplate subclass | ||
import ServerApi from "@/lib/api/ServerApi"; // Your ServerApi subclass | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
NPM Package Template © 2024 by Decatur Robotics is licensed under the MIT license. | ||
const api = new ServerApi(new ClientApi()); | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse, | ||
) { | ||
api.handle(req, res); | ||
} | ||
``` | ||
|
||
Next.js for Unified API © 2024 by Decatur Robotics is licensed under the MIT license. |
Oops, something went wrong.