http-helpers-serializy
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Helpers for integration serializy with http web clients

HTTP client helpers serializy

🚀 Installation

$ npm i -S http-helpers-serializy
# or using yarn
$ yarn add http-helpers-serializy

📚 Usage

import {
  deserializeRequestData,
  serializeResponseData,
} from 'http-helpers-serializy'
import { field, model } from 'serializy'

const SerializyModel = model({
  foo: field('Foo', 'any'),
})

const ErrorModel = model({
  message: field(e => (e ? JSON.stringify(e) : '')),
})

const structure = { Foo: '12345' }

const method = 'get'
const url = 'https://api.com/my-data'

const { data } = deserializeRequestData(SerializyModel, structure, {
  method,
  url,
})

// ...

const { data, error } = serializeResponseData(SerializyModel, structure, {
  method,
  url,
  isError: false,
  errorModel: ErrorModel,
  error: { message: 'bad response' },
})

📝 License

Licensed under the MIT License.

Package Sidebar

Install

npm i http-helpers-serializy

Weekly Downloads

5

Version

0.0.1

License

MIT

Unpacked Size

15.9 kB

Total Files

12

Last publish

Collaborators

  • acacode