Skip to content

Deprecate schema functions, replace with nuxt hooks #87

@mattmess1221

Description

@mattmess1221

Describe the feature

As of nuxt 3.14, using a function for the schema prints this to console.

WARN  Runtime config option apiParty.endpoints.foo.schema may not be able to be serialized.

I suggest using a hook that can update the endpoint. Hooks could also be added to intercept the API requests. Adding authorization, extra headers, request filtering, etc.

It would be used similarly to this.

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['nuxt-api-party'],
  apiParty: {
    endpoints: {
      foo: {
        url: 'http://localhost:8000'
      }
    }
  },
  // new hooks used instead of function
  hooks: {
    'api-party:resolve': async (id, endpoint) => {
      // set the schema value
      endpoint.schema = {
        // TODO
      }
    },
  }
})

Additional possible hooks

// plugins/api-auth.ts
export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.hooks.hook('api-party:fetch', async (request, {event}) => {
    // TODO
  })
})
// server/plugins/api-auth.ts
export default defineNitroPlugin((nitroApp) => {
  nitroApp.hooks.hook('api-party:request', async (request, {event}) => {
    // TODO
  })
})

Additional information

  • Would you be willing to help implement this feature?
  • Can you think of other implementations of this feature?

Final checks

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions