Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 8 hours ago
JSON representation
All you need to handle POST requests, file uploads, and api requests, in Next.js getServerSideProps.
- Host: GitHub
- URL: https://github.com/smeijer/next-runtime
- Owner: smeijer
- License: mit
- Created: 2021-09-11T10:13:13.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T08:24:48.000Z (about 2 months ago)
- Last Synced: 2024-12-01T03:37:39.213Z (12 days ago)
- Topics: api, forms, nextjs
- Language: TypeScript
- Homepage: https://next-runtime.meijer.ws/
- Size: 2.81 MB
- Stars: 590
- Watchers: 3
- Forks: 20
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- Awesome-NextJs - next-runtime - [documentation](https://next-runtime.meijer.ws/getting-started/1-introduction) (Nextjs Projects)
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
💻 📖 🤔 🚇 🚧
Gal Schlezinger
📖
Darius
💻 ⚠️
Umar Ahmed
💻
HIKARU KOBORI
💻
Koichi Kiyokawa
💻 ⚠️
Gorka Cesium
📖
Pandiyan Murugan
💻
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!