Adding New API
Usually when developing new feature, we need to call an API. One file is for one API end point
-
Create new typescript file inside
/apifolder Note.- Place it in existing folder if it still related. example place
getOpeningHour.tsinrestaurantfolder since it’s still related - Create new group if will create many new API and related
- Place it in
commonfolder if the API context is not specific to any feature
- Place it in existing folder if it still related. example place
-
import required module
import useHttp from "~/composables/useHttp";
- Create new
Type/Interfacaeto define API Response and Payload- Define API Response
Supposehungryhub.com/api/v5/config.jsonhave respond like this.{ "success": true, "data": { "enable_gift_card_feature": true, "we_travel_together_icon_url": "https://www.hungryhub.com/uploads/restaurants/tc/image/29/tc.png", "show_distance_on_search_page": false, "culture_locale": "th_TH", "available_locales": [ "th", "en" ], } } - Create new type for that response
type GetConfigAPIResponse = { success: boolean, data: { enableGiftCardFeature } } - Define API Response