Skip to content

Helper: URL path composable #103

@0xjogge

Description

@0xjogge

It's not always that we are fetching things directly via OpenFetch.

One example is PrimeVue's Upload component which takes an url an handles the post for you.

My idea was to have a composable like this:

const { path, responseType } = useApiPath('v1/files');

The path in this case would be http://localhost:1234/v1/files.

In the PrimeVue upload example that would look like this:

const { path, responseType } = useApiPath('v1/files');

<FileUpload
  name="files"
  :multiple="true"
  accept="image/*"
  :url="path"
>
  <template #empty>
    <span>Drag and drop files to here to upload.</span>
  </template>
</FileUpload>

I can see how it could be a bit out of scope for this project. But it would allow to use the type safety even for other things than fetching directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions