
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
next-api-composer
Advanced tools
A helper utility for composing Next.js API routes with per-method implementations
Your implementations of API Routes for your Next.js applications will be much easier with this library.
You have to code the API Routes like:
// api/example.ts
export default async (req, res) => {
if (req.method === 'GET') {
// do something
res.json({ foo: 'bar' });
return;
}
res.setHeader('Allow', 'GET');
if (req.method === 'OPTIONS') {
res.status(204).send(null);
} else {
res.status(405).send(null);
}
};
With this library:
// api/example.ts
export default nextApi({
GET: async (req, res) => {
// do something
res.json({ foo: 'bar' });
},
});
npm i next-api-composer
GET
POST
PUT
PATCH
DELETE
HTTP400BadRequest
, which extends RouteError
.RouteError
has a method send(res: Sendable)
.RouteError
is thrown in the handler, they'll be handled with calling the send
method of the error.RouteError
is thrown in the handler, the handler will emit HTTP 500 error.src/index.ts
.// api/example.ts
export default nextApi({
GET: async (req, res) => {
// Given, the function authenticate will return false
// if the request does not have a valid token in its HTTP header.
if (!authenticate(req)) {
throw new HTTP401Unauthorized();
}
// do something
res.json({ foo: 'bar' });
},
});
FAQs
A helper utility for composing Next.js API routes with per-method implementations
The npm package next-api-composer receives a total of 343 weekly downloads. As such, next-api-composer popularity was classified as not popular.
We found that next-api-composer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.