-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathindex.js
22 lines (19 loc) · 1.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import axios from 'axios';
const API=axios.create({baseURL:'http://localhost:5000'})
API.interceptors.request.use((req)=>{
if(localStorage.getItem('profile')){
req.headers.Authorization=`Bearer ${JSON.parse(localStorage.getItem('profile')).token}`;
}
return req;
});
// https://moment-internship.herokuapp.com/posts divyansh
export const fetchPosts= (page)=> API.get(`/posts?page=${page}`);
export const fetchPostsBySearch = (searchQuery) => API.get(`/posts/search?searchQuery=${searchQuery.search || 'none'}&tags=${searchQuery.tags}`);
export const createPost=(newPost)=>API.post('/posts',newPost);
export const likePost = (id) => API.patch(`/posts/${id}/likePost`);
export const updatePost=(id, updatedPost)=>API.patch(`/posts/${id}`,updatedPost);
export const deletePost=(id)=>API.delete(`/posts/${id}`);
export const fetchPost=(id)=>API.get(`/posts/${id}`);
export const signIn=(formData)=>API.post('/user/signin',formData);
export const signUp=(formData)=>API.post('/user/signup',formData);
export const comment = (value, id) => API.post(`/posts/${id}/commentPost`, { value });