0.4.2 • Published 4 months ago

restmix v0.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Restmix

pub package

A lightweight Typescript friendly requests manager for rest apis

:books: Documentation

import { useApi, ApiResponse } from 'restmix';

const api = useApi();

interface TodoItemContract {
  userId: number;
  id: number;
  title: string;
  completed: boolean;
}

const res: ApiResponse<TodoItemContract> = await api.get<TodoItemContract>(
  "https://jsonplaceholder.typicode.com/todos/1",
);
if (res.ok) {
  // status code is in the 200/299 range
  const data: TodoItemContract = res.data;
} else {
  // status code is > 299
  const responseStatus: number = res.status;
  throw new Error(res.statusText)
}

It is the same as fetch except that it takes care of the response body parsing and delivers typed data

interface ApiResponse<T = Record<string, any> | Array<any>> {
  ok: boolean;
  url: string;
  headers: Record<string, string>;
  status: number;
  statusText: string;
  data: T;
  text: string;
}
0.4.2

4 months ago

0.4.1

5 months ago

0.4.0

5 months ago

0.3.1

7 months ago

0.3.0

8 months ago

0.2.0

9 months ago

0.1.0

1 year ago

0.0.7

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.6

1 year ago

0.0.1

2 years ago