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

32 lines
690 B
TypeScript
Raw Normal View History

2020-11-04 14:39:57 +03:00
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> = {
2020-11-04 14:39:57 +03:00
method: Method.GET,
url: '/action-adventure',
transformResponseData(data: Movie[]) {
return {
items: data,
}
}
2020-11-04 14:39:57 +03:00
};
export type MoviesResponse = {
items: Movie[],
}
export const MovieEndpoint: Endpoint<MovieResponse, void, MovieParams> = {
method: Method.GET,
url: ({ id }) => `/action-adventure/${id}`,
};
export type MovieParams = Readonly<{ id: React.Key }>;
export type MovieResponse = Movie[];