Skip to content

Request: How to post using navigator.sendBeacon #2544

@chris-martin

Description

@chris-martin

Description

I have a web client that is currently using openapi-fetch to make a POST API call. I would like to modify it to make that request via navigator.sendBeacon instead. See the docs there for a description of the circumstance in which this is useful.

Proposal

If is isn't desirable to make a code change to support a browser-specific API, merely making a documentation improvement might be sufficient to pave the path here. I think it suffices to provide as an argument to createClient something like

  fetch: async (input: Request) => {
    window.navigator.sendBeacon(input.url, input.body)
    return new Response('') // sendBeacon doesn't return a response
  }

Does this seem like a smart enough way to go about it?

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestopenapi-fetchRelevant to the openapi-fetch library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions