Skip to main content

3 posts tagged with "API"

View All Tags

· 2 min read
Markus Blomqvist

With the help of the early community of Next REST Framework, we've made the framework significantly more robust for production use serving better developer needs during the past weeks. Some examples of this are the awesome new features like validating query parameters and adding support for an auto-generated local OpenAPI specification.

Query parameter validation

You can now validate also query parameters with Zod schemas in addition to validating only the request bodies simply by passing the validation schema to your input object:

// src/pages/api/todos.ts

import { defineEndpoints } from 'next-rest-framework/client';
import { z } from 'zod';

export default defineEndpoints({
POST: {
input: {
// ...
query: z.object({
page: z.string()
})
}
// Rest of your logic.
}
});

This way all requests with query parameters not matching to the provided schema will get an error response. In addition to this, the query parameter definition is now also included into the generated OpenAPI spec!

Local OpenAPI spec

To avoid unnecessary filesystem calls and prefer caching, Next REST Framework now relies on a local openapi.json file that will contain your auto-generated OpenAPI spec. This addition also makes the framework usable in serverless environments like Vercel and allows you to use the generated OpenAPI spec for whatever purposes you want to.

The openapi.json file will be regenerated during local development whenever you call any of the reserved OpenAPI paths:

  • /api
  • /api/openapi.json
  • /api/openapi.yaml

Additionally, we've fixed a list of issues brought up by the community and improved the stability of the framework all together.

· One min read
Markus Blomqvist

Next REST Framework has been out for around two months now, experiencing a lot breaking changes since the initial release. After the first test users battle-testing the framework and resolving the first issues, it's great to announce some new updates that I've been working on during the past two months.

Here are some of the improvements that Next.js has experienced so far since the initial release:

  • Support for projects using src folder.
  • Major stability improvements to the public API - better compatibility with other Next.js API routes.
  • Support for typed query parameters. Thanks @rliang for the issue!
  • Documentation improvements.
  • Custom Swagger UI layout.
  • Other minor improvements.

v0.3.4 being out with additional improvements to the typings, you no longer need to have both Zod and installed to use the framework, resulting in a more lightweight approach wo use the framework.

· One min read
Markus Blomqvist

Although Next.js has been a valid option for full-stack applications for a while now, a lot of developers have limited the use of it only for the frontend parts of their applications. The Next.js API Routes however, offer a great way to build a backend for your dynamic applications.

The Next.js ecosystem has been evolving rapidly in the past few years and we've seen great server-side frameworks, like tRPC, emerging. Similar choices for REST APIs have been lacking and personally I've been reinventing the wheel over and over again on every Next.js backend I've been building during the past few years. The learnings from repeating the same things from project to project led to developing Next REST Framework, which is an open-source, lightweight, easy-to-use set of tools to build type-safe, self-documenting HTTP REST APIs with Next.js.

The first problem that Next REST Framework aims to solve lies in ensuring that your backend is type-safe, using TypeScript and object-schema validation with Zod. Secondly, Next REST Framework self-documents your API straight from your business logic similarly to other popular REST frameworks like Fast API and Django REST Framework and not from endless lines of open API JSDoc annotations etc.