Files
DefectingCat 5e1f58a144 Add search API
* update prisma
* Add search API in page
* add API with fetch
* Update search with global state
2022-02-08 20:40:08 +08:00

24 lines
425 B
TypeScript

import { SearchType } from 'lib/API/types';
const search = async (q: string, page = 1) => {
const body = {
q,
page,
};
const response = await fetch('/api/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
if (response.ok) {
const result: SearchType = await response.json();
return result;
}
};
export { search };