This is an example of how to use the Unkey API with NestJS.
Table of Contents
- Go to /settings/root-keys and click on the "Create New Root Key" button.
- Enter a name for the key.
- Select the following workspace permissions: create_key, read_key, encrypt_key and decrypt_key.
- Click "Create".
- Go to https://app.unkey.com/apis and click on the "Create New API" button.
- Give it a name.
- Click "Create".
- Click "Create Key" in the top right corner.
- Feel the form with any key information you want or leave it empty.
- Click "Create"
- Copy the key and save it somewhere safe.
- Clone the repository to your local machine.
git clone <repo-url>
cd /path/to/repo
- Duplicate the
.env.example
file and rename it to.env
.
cp .env.example .env
-
Replace your API key in the
.env
file. -
Install the dependencies.
pnpm install
- Run the application.
pnpm run start
- Test the public route as a guest:
curl http://localhost:3000/api/v1/public
- Test the protected route, which requires valid authorization:
curl http://localhost:3000/api/v1/protected -H "Authorization: Bearer <YOUR_API_KEY>"
This project is licensed under the MIT License - see the LICENSE file for details.