Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/smeijer/next-runtime

All you need to handle POST requests, file uploads, and api requests, in Next.js getServerSideProps.
https://github.com/smeijer/next-runtime

api forms nextjs

Last synced: about 2 months ago
JSON representation

All you need to handle POST requests, file uploads, and api requests, in Next.js getServerSideProps.

Awesome Lists containing this project

README

        

![banner](docs/public/banner.png)

All you need to handle `POST` requests and file uploads in [`getServerSideProps`](https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering).

## Documentation

All documentation and guides can be found at [next-runtime.meijer.ws](https://next-runtime.meijer.ws/).

## Features

next-runtime aims to move more logic to the "runtime part" of your Next.js server, and less static site generation. With proper cache headers, every server is an (incremental) static site generator.

To achieve that, we provide you a convenient API to:

- Handle POST requests in `getServerSideProps`.
- Handle file uploads in `getServerSideProps`.
- Easily manage headers and cookies.
- Reuse `getServerSideProps` as zero-config JSON api.

## Usage

In case you're not the documentation type of person, here's a quick example to get you up and running. Please consult [the docs](https://next-runtime.meijer.ws/) if this leaves you with questions.

```js
import fs from 'fs';
import { handle, json } from 'next-runtime';

export const getServerSideProps = handle({
async upload({ file, stream }) {
stream.pipe(fs.createWriteStream(`/uploads/${file.name}`));
},

async get({ params, query }) {
return json({ name: 'Stephan Meijer' });
},

async post({ req: { body } }) {
return json({ message: 'Thanks for your submission!' });
},
});

export default function Home({ name, message }) {
if (message) {
return

{message}

;
}

return (



submit

);
}
```

## Sponsor

Are you, or your employer, a satisfied user of this, or any of [my other projects](https://meijer.ws/open-source). Then please [consider sponsoring](https://github.com/sponsors/smeijer) my work so I can dedicate more time to maintaining this kind of projects.

## Contributing

Please check [contributing.md](/CONTRIBUTING.md). It contains info about the structure of this repo
to help you get up and running.

## Contributors

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



Stephan Meijer
Stephan Meijer

💻 📖 🤔 🚇 🚧
Gal Schlezinger
Gal Schlezinger

📖
Darius
Darius

💻 ⚠️
Umar Ahmed
Umar Ahmed

💻
HIKARU KOBORI
HIKARU KOBORI

💻
Koichi Kiyokawa
Koichi Kiyokawa

💻 ⚠️
Gorka Cesium
Gorka Cesium

📖

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!