Skip to content

Conversation

@mattmess1221
Copy link
Contributor

πŸ”— Linked issue

Related to #87 and #88

❓ 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

I'm marking this as a draft because some decisions need to be made about which endpoints will trigger a hook.

Should client -> server -> backend send a hook on the client and server, or just the server?

πŸ“ Checklist

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

@netlify
Copy link

netlify bot commented Nov 6, 2024

βœ… Deploy Preview for nuxt-api-party ready!

Name Link
πŸ”¨ Latest commit 7053472
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt-api-party/deploys/67dbc8e0b41659000845623d
😎 Deploy Preview https://deploy-preview-89--nuxt-api-party.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mattmess1221
Copy link
Contributor Author

Build failures may be related to nuxt/nuxt#29263

@johannschopplich
Copy link
Owner

Another banger from you. 🀯 Thanks a lot, @mattmess1221!

@froozeify
Copy link
Contributor

Those hooks are what I was looking for.

I wanted to dynamically update the Authorization headers based on the request received (i.e If defined in the request as Bearer don't change it and else I'll be adding the Basic header - for an oauth app with custom oauth server)

@margaretjoanmiller
Copy link

@froozeify did it end up working out? was going to use the hooks to set the auth token header but I'm wondering if with refresh tokens it would be more trouble than it's worth

@mattmess1221
Copy link
Contributor Author

mattmess1221 commented Mar 18, 2025

I managed to work around the build typechecking issues by importing directly from nitropack/runtime instead of through #imports. I'm thinking it may be a good idea to just avoid #imports altogether in the rest of the project just for consistency.

Other things I've done

  • Removed hooks from server-side $api utility. I figure the user should explicitly pass any headers, fetch hooks, etc if they need to customize it from the server.
  • Added dynamic hook keys based on the endpoint id for ease of registration. e.g. api-party:request will trigger for all request hooks, but api-party:request:jsonPlaceholder will only trigger for the jsonPlaceholder endpoint.

Docs probably need some work.

@mattmess1221 mattmess1221 marked this pull request as ready for review March 18, 2025 18:39
@johannschopplich
Copy link
Owner

@mattmess1221 Thanks a lot for the updates and patience on review. Great work! πŸ™ Let's release and iterate.

Some thoughts:

  • Using nitropack/runtime is fine, I agree, since the types are broken otherwise. It will be deprecated in Nitro v3, but we're long before that.
  • Love the api-party:request:jsonPlaceholder approach!

@johannschopplich johannschopplich merged commit 68f627d into johannschopplich:main Mar 20, 2025
7 checks passed
@mattmess1221 mattmess1221 deleted the feature/fetch-hooks branch May 14, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants