home and about page
This commit is contained in:
43
yoga-app/src/api/strapi/strapi-client.ts
Normal file
43
yoga-app/src/api/strapi/strapi-client.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import httpClient from "@/api/http-client";
|
||||
import {Payload} from "@/types/generated-strapi-interfaces/common/Payload";
|
||||
|
||||
const STRAPI_URL = process.env.STRAPI_URL;
|
||||
|
||||
class StrapiClient{
|
||||
|
||||
constructor(private strapiUrl: string = "http://localhost:1337") {
|
||||
}
|
||||
public getImageUrl(imagePath: string){
|
||||
return this.strapiUrl + imagePath;
|
||||
}
|
||||
public async httpGet(path: string){
|
||||
return await httpClient.httpGet(this.strapiUrl + path);
|
||||
}
|
||||
public async httpGetJson<T>(url: string): Promise<Payload<T>>{
|
||||
const response = await this.httpGet(url);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
public async findContentType<T>(contentType: string,options?: FindContentOptions): Promise<Payload<T>>{
|
||||
const searchParams = new URLSearchParams();
|
||||
if ( options?.populateAll ){
|
||||
searchParams.append("populate","*");
|
||||
}
|
||||
if (options?.localeAll){
|
||||
searchParams.append("_locale","all");
|
||||
}
|
||||
|
||||
|
||||
|
||||
const response = await this.httpGet("/api/"+contentType+"?"+searchParams.toString());
|
||||
return await response.json();
|
||||
}
|
||||
}
|
||||
|
||||
export interface FindContentOptions{
|
||||
populateAll?: boolean;
|
||||
localeAll?: boolean;
|
||||
}
|
||||
|
||||
const client = new StrapiClient(STRAPI_URL);
|
||||
export default client;
|
||||
Reference in New Issue
Block a user