SYNC-HP用のサンプル
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
825B

  1. import { Guitar } from "../type/guitars";
  2. /**
  3. * Guitar情報取得処理
  4. */
  5. export const fetchGuitars = async (): Promise<Guitar[]> => {
  6. // StrapiのAPIを呼び出し
  7. const response = await fetch(
  8. `${process.env.NEXT_PUBLIC_STRAPI_URL}/api/guitars?populate=*`
  9. );
  10. // apiのresponseからdata部のみ取り出し
  11. const guitars: Guitar[] = await response.json().then((json) => json.data);
  12. return guitars;
  13. };
  14. /**
  15. * Guitar情報取得処理
  16. */
  17. export const fetchGuitarDetail = async (id: string): Promise<Guitar> => {
  18. // StrapiのAPIを呼び出し
  19. const response = await fetch(
  20. `${process.env.NEXT_PUBLIC_STRAPI_URL}/api/guitars/${id}?populate=*`
  21. );
  22. // apiのresponseからdata部のみ取り出し
  23. const guitar: Guitar = await response.json().then((json) => json.data);
  24. return guitar;
  25. };