add service
This commit is contained in:
1 parent
69fdb3a933
commit
b74faa3997
6 files changed
+64
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import httpClient from '../instance';
|
||||
import { IArticle } from './types';
|
||||
|
||||
class ArticleService {
|
||||
name = 'articles';
|
||||
|
||||
getAll(): Promise<IArticle> {
|
||||
return httpClient.get(`/${this.name}`);
|
||||
}
|
||||
|
||||
get(id: number): Promise<IArticle> {
|
||||
return httpClient.get(`/${this.name}/${id}`);
|
||||
}
|
||||
|
||||
create(data: IArticle): Promise<IArticle> {
|
||||
return httpClient.post(`/${this.name}`, data);
|
||||
}
|
||||
|
||||
update(id: number, data: IArticle): Promise<IArticle> {
|
||||
return httpClient.put(`/${this.name}/${id}`, data);
|
||||
}
|
||||
|
||||
delete(id: number): Promise<IArticle> {
|
||||
return httpClient.delete(`/${this.name}/${id}`);
|
||||
}
|
||||
|
||||
deleteAll(): Promise<IArticle> {
|
||||
return httpClient.delete(`/${this.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
export default new ArticleService();
|
||||
@@ -0,0 +1,4 @@
|
||||
export interface IArticle {
|
||||
id: number;
|
||||
title: string;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import ArticleService from './article/service';
|
||||
|
||||
export { ArticleService };
|
||||
@@ -0,0 +1,12 @@
|
||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
|
||||
const httpClient: AxiosInstance = axios.create({
|
||||
timeout: 30000,
|
||||
headers: {
|
||||
'Content-type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
// const httpClient = (options: AxiosRequestConfig): Promise<AxiosResponse> => instance.request(options);
|
||||
|
||||
export default httpClient;
|
||||
Reference in new issue
Block a user