v2.0.0
What's Changed
- Add transformers to
makeService
andmakeFetcher
by @danielweinmann in #21 - Document baseOptions and add disclaimer by @danielweinmann in #26
- Expose getJson and getText as typedResponse options by @danielweinmann in #25
- Drop string transformations from this library, use
string-ts
instead by @gustavoguichard in #27
BREAKING Changes:
Dropped string transformations
String transformations such as kebabToCamel
and etc were removed from this library. We recommend replacing it by string-ts which is much more powerful and fully featured.
// BEFORE v2
import { makeService, kebabToCamel } from 'make-service'
const service = makeService("https://example.com/api")
const response = await service.get("/users")
const users = await response.json(
z
.array(z.object({ "first-name": z.string(), contact: z.object({ "home-address": z.string() }) }))
.transform(kebabToCamel)
)
// AFTER v2
import { makeService } from 'make-service'
import { deepCamelKeys } from 'string-ts'
const service = makeService("https://example.com/api")
const response = await service.get("/users")
const users = await response.json(
z
.array(z.object({ "first-name": z.string(), contact: z.object({ "home-address": z.string() }) }))
.transform(deepCamelKeys)
)
With string-ts
you don't need to specify the input casing of the string, you only need to specify the target casing. 🔥
Changes to the second argument of makeService
Now the second argument to makeService
and makeFetcher
functions is baseOptions
which is an object with headers
, requestTransformer
, and responseTransformer
. You can use the new transformers to pre-process your Request
before sending it or post-process your Response
just after fetching.
This allows further customization of this library such as creating adapters for APIs that will transform the payloads back and forth.
Turning the second parameter into an object will also allow future new APIs to come to this library.
How to migrate:
You just need to send your former baseHeaders
in the baseOptions.headers
now as so:
// Versions < 2.0.0
const service = makeService('https://google.com', new Headers({ authorization: "Bearer 123" }))
// From versions >= 2.0.0
const service = makeService('https://google.com', {
headers: new Headers({ authorization: "Bearer 123" }),
})
Acknowledgements
I appreciate all the effort by @danielweinmann, @diogob , and the team at SeasonedSoftware that made it to this release.
Full Changelog: v1.1.0...v2.0.0