Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file.

## [3.0.0] - Unreleased
## [3.0.0-beta.1] - 2026-06-15

### Changed

Expand Down Expand Up @@ -143,7 +143,7 @@ All notable changes to this project will be documented in this file.
- `UrlBuilder` a class to build URLs through a template;
- `RepositoryHttp` an implementation of `Repository` interface to fetch data through `HttpClient`.

[3.0.0]: https://github.com/volverjs/data/compare/v2.0.5...v3.0.0
[3.0.0-beta.1]: https://github.com/volverjs/data/compare/v2.0.5...v3.0.0-beta.1
[2.0.5]: https://github.com/volverjs/data/compare/v2.0.4...v2.0.5
[2.0.4]: https://github.com/volverjs/data/compare/v2.0.3...v2.0.4
[2.0.3]: https://github.com/volverjs/data/compare/v2.0.2...v2.0.3
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The `HttpClient` class is a wrapper around [`ky`](https://github.com/sindresorhu
import { HttpClient } from '@volverjs/data'

const client = new HttpClient({
prefixUrl: 'https://my.api.com'
prefix: 'https://my.api.com'
})
const response = await client.get({
template: ':endpoint/:action?/:id',
Expand Down Expand Up @@ -119,7 +119,7 @@ class User {
}

const client = new HttpClient({
prefixUrl: 'https://my.api.com'
prefix: 'https://my.api.com'
})

const repository = new RepositoryHttp<User>(client, 'users/:group?/:id?', {
Expand Down Expand Up @@ -152,7 +152,7 @@ import App from './App.vue'

const app = createApp(App)
const httpClientPlugin = createHttpClient({
prefixUrl: 'https://my.api.com'
prefix: 'https://my.api.com'
})

app.use(httpClientPlugin, {
Expand Down Expand Up @@ -180,7 +180,7 @@ import { createHttpClient, useHttpClient } from '@volverjs/data/vue'
import { computed, ref } from 'vue'

createHttpClient({
prefixUrl: 'https://my.api.com'
prefix: 'https://my.api.com'
})

const { client } = useHttpClient()
Expand Down Expand Up @@ -569,7 +569,7 @@ With `scope` parameter on `createHttpClient()` multiple `httpClient` instances c
<script lang="ts" setup>
import { createHttpClient } from '@volverjs/data/vue'

createHttpClient({ scope: 'v2Api', prefixUrl: 'https://my.api.com/v2' })
createHttpClient({ scope: 'v2Api', prefix: 'https://my.api.com/v2' })

const { requestGet } = useHttpClient('v2Api')

Expand All @@ -592,7 +592,7 @@ The `global` `httpClient` instance cannot be removed.
<script lang="ts" setup>
import { createHttpClient, removeHttpClient } from '@volverjs/data/vue'

createHttpClient({ scope: 'v2Api', prefixUrl: 'https://my.api.com/v2' })
createHttpClient({ scope: 'v2Api', prefix: 'https://my.api.com/v2' })

const { requestGet } = useHttpClient('v2Api')

Expand Down
2 changes: 1 addition & 1 deletion docs/HttpClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type HttpClientOptions = {
headers?: HttpClientHeaders
json?: unknown
parseJson?: (text: string) => unknown // default: JSON.parse()
prefixUrl?: URL | string
prefix?: URL | string
retry?: HttpClientRetryOptions | number
timeout?: number | false // default: 10000
hooks?: HttpClientHooks
Expand Down
2 changes: 1 addition & 1 deletion docs/RepositoryHttp.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class User {
}

const client = new HttpClient({
prefixUrl: 'https://api.example.com'
prefix: 'https://api.example.com'
})

const repository = new RepositoryHttp<User>(client, 'users/:group?/:id?', {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
},
"dependencies": {
"abort-controller": "^3.0.0",
"ky": "^1.14.3",
"ky": "^2.0.2",
"node-fetch": "^3.3.2",
"qs": "^6.15.2",
"web-streams-polyfill": "^4.3.0"
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ export { HTTPError, TimeoutError }
export class HttpClient implements HttpClientInstance {
private _client: KyInstance
private _urlBuilder: UrlBuilderInstance
private _prefixUrl: string | URL | undefined
private _prefix: string | URL | undefined

constructor(options: HttpClientInstanceOptions = {}) {
const { client, urlBuilder, searchParams, ...clientOptions } = options
this._client = client ?? ky.create(clientOptions)
this._urlBuilder = urlBuilder ?? new UrlBuilder(searchParams)
this._prefixUrl = clientOptions.prefixUrl
this._prefix = clientOptions.prefix
}

public get = (
Expand Down Expand Up @@ -183,7 +183,7 @@ export class HttpClient implements HttpClientInstance {
public extend = (options: HttpClientOptions = {}) => {
const { searchParams, ...clientOptions } = options
this._client = this._client.extend(clientOptions)
this._prefixUrl = clientOptions.prefixUrl ?? this._prefixUrl
this._prefix = clientOptions.prefix ?? this._prefix
this._urlBuilder.extend(searchParams ?? {})
}

Expand Down Expand Up @@ -216,7 +216,7 @@ export class HttpClient implements HttpClientInstance {
): HttpClientInput {
const toReturn = HttpClient.buildUrl(url, options, this._urlBuilder)
if (
this._prefixUrl
this._prefix
&& typeof toReturn === 'string'
&& toReturn?.startsWith('/')
) {
Expand Down
6 changes: 3 additions & 3 deletions src/RepositoryHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type RepositoryHttpOptions<TRequest, TResponse = TRequest> = {
* @default undefined
* @example
* ```typescript
* addHttpClient('v2', { prefixUrl: 'https://myapi.com/v2' })
* addHttpClient('v2', { prefix: 'https://myapi.com/v2' })
* const { read } = useRepositoryHttp<{ id: string }>('users/?:id', { httpClientScope: 'v2' })
* read({ id: 1 })
* //=> GET https://myapi.com/v2/?id=1
Expand All @@ -42,7 +42,7 @@ export type RepositoryHttpOptions<TRequest, TResponse = TRequest> = {
* @default undefined
* @example
* ```typescript
* const repository = new RepositoryHttp(client, 'users/?:id', { httpClientOptions: { prefixUrl: 'https://example.com' } })
* const repository = new RepositoryHttp(client, 'users/?:id', { httpClientOptions: { prefix: 'https://example.com' } })
* repository.read({ id: 1 })
* //=> GET https://example.com/?id=1
* ```
Expand Down Expand Up @@ -184,7 +184,7 @@ implements Repository<TRequest, TResponse> {
this._httpClientOptions = options.httpClientOptions
}
if (options?.class && !options?.responseAdapter) {
const OptionsClass = options.class as new (...args: any[]) => TResponse
const OptionsClass = options.class
this._responseAdapter = (raw) => {
return Array.isArray(raw)
? raw.map(rawItem => new OptionsClass(rawItem))
Expand Down
4 changes: 2 additions & 2 deletions src/vue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class HttpClientPlugin extends HttpClient {
*
* const app = createApp(App)
* const client = createHttpClient({
* prefixUrl: 'https://my.api.com'
* prefix: 'https://my.api.com'
* })
* app.use(client)
* ```
Expand All @@ -97,7 +97,7 @@ class HttpClientPlugin extends HttpClient {
*
* const app = createApp(App)
* const client = createHttpClient({
* prefixUrl: 'https://my.api-v2.com',
* prefix: 'https://my.api-v2.com',
* scope: 'apiV2'
* })
*
Expand Down
6 changes: 3 additions & 3 deletions test/httpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('httpClient', () => {
it('should make a GET request with template and query parameters and prefix url', async () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))
const client = new HttpClient({
prefixUrl: 'https://myapi.com/v1',
prefix: 'https://myapi.com/v1',
})
const data = (await client
.get({
Expand All @@ -79,7 +79,7 @@ describe('httpClient', () => {
it('should make a GET request with error', async () => {
fetchMock.mockResponseOnce(() => ({ status: 404 }))
const client = new HttpClient({
prefixUrl: 'https://myapi.com/v1',
prefix: 'https://myapi.com/v1',
})
try {
await client
Expand All @@ -101,7 +101,7 @@ describe('httpClient', () => {
it('should abort a GET request', async () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))
const client = new HttpClient({
prefixUrl: 'https://myapi.com/v1',
prefix: 'https://myapi.com/v1',
})
const { responsePromise, abort, signal } = client.request(
'get',
Expand Down
12 changes: 6 additions & 6 deletions test/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('repositoryHttp', () => {
it('should read', async () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))
const client = new HttpClient({
prefixUrl: 'https://myapi.com/v1',
prefix: 'https://myapi.com/v1',
})
const repository = new RepositoryHttp<{ id: string }>(client, ':type')
const { responsePromise } = repository.read({
Expand All @@ -31,7 +31,7 @@ describe('repositoryHttp', () => {
})
it('should stop a read request', async () => {
const client = new HttpClient({
prefixUrl: 'https://myapi.com/v1',
prefix: 'https://myapi.com/v1',
})
const repository = new RepositoryHttp(client, ':type?')
const { responsePromise, abort } = repository.read({})
Expand All @@ -43,7 +43,7 @@ describe('repositoryHttp', () => {
it('should merge 2 equals read requests', async () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))
const client = new HttpClient({
prefixUrl: 'https://myapi.com/v1',
prefix: 'https://myapi.com/v1',
})
const repository = new RepositoryHttp<{ id: string }>(client, ':type')
const { responsePromise: responsePromise1 } = repository.read({
Expand All @@ -69,7 +69,7 @@ describe('repositoryHttp', () => {
it('should merge 2 equals read request, first aborted', async () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))
const client = new HttpClient({
prefixUrl: 'https://myapi.com/v1',
prefix: 'https://myapi.com/v1',
})
const repository = new RepositoryHttp<{ id: string }>(client, ':type')
const { responsePromise: responsePromise1, abort } = repository.read({
Expand All @@ -95,7 +95,7 @@ describe('repositoryHttp', () => {
it('should merge 2 equals read request, second aborted', async () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))
const client = new HttpClient({
prefixUrl: 'https://myapi.com/v1',
prefix: 'https://myapi.com/v1',
})
const repository = new RepositoryHttp<{ id: string }>(client, ':type')
const { responsePromise: responsePromise1 } = repository.read({
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('repositoryHttp', () => {
},
})
const client = new HttpClient({
prefixUrl: 'https://myapi.com/v1',
prefix: 'https://myapi.com/v1',
})
const repository = new RepositoryHttp<{ id: string }>(client, ':type')
const { responsePromise } = repository.read({ type: 'alpha' })
Expand Down
16 changes: 8 additions & 8 deletions test/vueHttpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('vue useHttpClient', () => {
it('should make a GET request with template and query parameters and prefix url', async () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))
createHttpClient({
prefixUrl: 'https://myapi.com/v1',
prefix: 'https://myapi.com/v1',
scope: 'myApi',
})
const { requestGet } = useHttpClient('myApi')
Expand All @@ -99,7 +99,7 @@ describe('vue useHttpClient', () => {
it('should make a GET request with error', async () => {
fetchMock.mockResponseOnce(() => ({ status: 404 }))
createHttpClient({
prefixUrl: 'https://myapi.com/v2',
prefix: 'https://myapi.com/v2',
scope: 'myApi2',
})
const { requestGet } = useHttpClient('myApi2')
Expand All @@ -122,7 +122,7 @@ describe('vue useHttpClient', () => {
it('should abort a GET request', async () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))
createHttpClient({
prefixUrl: 'https://myapi.com/v3',
prefix: 'https://myapi.com/v3',
scope: 'myApi3',
})
const { request } = useHttpClient('myApi3')
Expand All @@ -140,7 +140,7 @@ describe('vue useHttpClient', () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))

createHttpClient({
prefixUrl: 'https://myapi.com/v4',
prefix: 'https://myapi.com/v4',
scope: 'myApi4',
})

Expand All @@ -156,7 +156,7 @@ describe('vue useHttpClient', () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))

createHttpClient({
prefixUrl: 'https://myapi.com/v5',
prefix: 'https://myapi.com/v5',
scope: 'myApi5',
})

Expand All @@ -173,7 +173,7 @@ describe('vue useHttpClient', () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))

createHttpClient({
prefixUrl: 'https://myapi.com/v6',
prefix: 'https://myapi.com/v6',
scope: 'myApi6',
})

Expand All @@ -187,7 +187,7 @@ describe('vue useHttpClient', () => {

try {
createHttpClient({
prefixUrl: 'https://myapi.com/v6',
prefix: 'https://myapi.com/v6',
scope: 'myApi6',
})
}
Expand All @@ -202,7 +202,7 @@ describe('vue useHttpClient', () => {
fetchMock.mockResponseOnce(JSON.stringify([{ id: '12345' }]))

createHttpClient({
prefixUrl: 'https://myapi.com/v7',
prefix: 'https://myapi.com/v7',
scope: 'myApi7',
})

Expand Down
4 changes: 2 additions & 2 deletions test/vueRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const fetchMock = createFetchMock(vi)

// Install a plugin onto VueWrapper
const httpClient = createHttpClient({
prefixUrl: 'https://myapi.com/v1',
prefix: 'https://myapi.com/v1',
})

const component = {
Expand All @@ -30,7 +30,7 @@ const componentHttpClientV2 = {
template: '<div />',
setup: () => {
createHttpClient({
prefixUrl: 'https://myapi.com/v2',
prefix: 'https://myapi.com/v2',
scope: 'v2',
})
const { read } = useRepositoryHttp<{ id: string }>(':type', {
Expand Down
Loading