This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
react-rest-request/examples/movies/src/endpoint.ts
Dmitriy Pleshevskiy 651e09bc31 feat: extract types from endpoint
chore: change example and readme

Closes #24
2020-12-19 13:26:22 +03:00

31 lines
689 B
TypeScript

import { Endpoint, Method } from 'react-rest-request';
export type Movie = Readonly<{
id: number;
title: string;
posterURL: string;
imdbId: string;
}>
export const MoviesEndpoint: Endpoint<MoviesResponse, void> = {
method: Method.GET,
url: '/action-adventure',
transformResponseData(data: Movie[]) {
return {
items: data,
}
}
};
export type MoviesResponse = {
items: Movie[],
}
export const MovieEndpoint: Endpoint<MovieResponse, never, MovieParams> = {
method: Method.GET,
url: ({ id }) => `/action-adventure/${id}`,
};
export type MovieParams = Readonly<{ id: React.Key }>;
export type MovieResponse = Movie;