-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from 2308-Bread/feat/api_integration
Feat/api integration
- Loading branch information
Showing
7 changed files
with
98 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ApiResponse } from './apiTypes'; | ||
|
||
export const fetchBreadsForCountry = (countryName: string): Promise<ApiResponse> => { | ||
return fetch(`https://rails-bread-face5cd9a02c.herokuapp.com/api/v1/countries/${countryName}`) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
}) | ||
.catch(error => console.error("There was a problem with the fetch operation:", error)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Define a structure for the attributes of bread and country | ||
export interface BreadAttributes { | ||
name: string; | ||
description: string; | ||
recipe: string; | ||
} | ||
|
||
export interface CountryAttributes { | ||
name: string; | ||
description: string; | ||
} | ||
|
||
// Define the main data structure for both bread and country | ||
export interface BreadData { | ||
id: string; | ||
type: string; | ||
attributes: BreadAttributes; | ||
} | ||
|
||
export interface CountryData { | ||
id: string; | ||
type: string; | ||
attributes: CountryAttributes; | ||
} | ||
|
||
// Define the top-level structure of the API response | ||
export interface ApiResponse { | ||
country: { | ||
data: CountryData; | ||
}; | ||
breads: { | ||
data: BreadData[]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters