Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add examples for index.ts files on server routes #23390

Merged
merged 4 commits into from Sep 27, 2023

Conversation

filipweidemann
Copy link
Contributor

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

While getting to know how Nuxt handles server routes I stumbled over the required naming of the .ts files to create a rather common API structure:

  • /api/project/
  • /api/project/[id]
  • /api/project/[id]/invite

The docs didn't convey that handling the "root" namespace of you API requires setting one (or multiple) index.ts files inside of the project directory so that /api/project will be handled correctly and with potentially multiple HTTP verbs and different logic.

This is obviously a quite common technique in all kinds of module-situations in the JS world but I thought it would be cool to include this as a short and concise example alongside the existing docs about the file router.

I am also aware that many things are more or less directly related to nitro and may or may not need to be directly documented inside the Nuxt docs but since this documentation is the first contact point for everyone learning Nuxt I though that I could help to make this more clear for all future learners!

If you have any question or opinion about this, please ask straight away. I'd love to make this even better if needed. :)

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@stackblitz
Copy link

stackblitz bot commented Sep 24, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@nuxt-studio
Copy link

nuxt-studio bot commented Sep 24, 2023

Live Preview ready!

Name Edit Preview Latest Commit
Nuxt Docs Edit on Studio ↗︎ View Live Preview 1c563cd

filipweidemann and others added 2 commits September 26, 2023 19:20
Co-authored-by: Sébastien Chopin <seb@nuxtlabs.com>
Co-authored-by: Sébastien Chopin <seb@nuxtlabs.com>
@filipweidemann
Copy link
Contributor Author

Thanks @Atinux. I committed your suggestions.

@Atinux Atinux merged commit d788577 into nuxt:main Sep 27, 2023
4 checks passed
@github-actions github-actions bot mentioned this pull request Sep 27, 2023
@github-actions github-actions bot mentioned this pull request Sep 28, 2023
manniL pushed a commit that referenced this pull request Dec 11, 2023
Co-authored-by: Sébastien Chopin <seb@nuxtlabs.com>
Co-authored-by: Sébastien Chopin <seb@nuxt.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants