#react api
14 messages · Page 1 of 1 (latest)
Check the course, they might have an updated link to fetch the data from.
Either the link is wrong or its not the API link anymore. 404 error = removed/deleted
You should check with the course and ask for an updated link.
o prepare for the completion of this exercise, you need to include the API JavaScript file in your code.
Add the following code to your index.html.
1
<script src="https://raw.githubusercontent.com/Meta-Front-End-Developer-PC/capstone/master/api.js"></script>
The API has two functions that you can use in your code:
fetchAPI(date) - This function accepts a date as a parameter and returns an array of available reservation times for the provided date
submitAPI(formData) - This function accepts the booking form data as a parameter and will return true if the data was successfully submitted.
these are the instructions
I looked at some projects of other people this is the API they are using
https://github.com/alexismenest/meta-front-end-developer-capstone/blob/main/src/utils/fakeAPI.js
the question im about to ask might look stupid , like how did this data come from ???????? const seededRandom = function (seed) {
var m = 2 ** 35 - 31;
var a = 185852;
var s = seed % m;
return function () {
return (s = (s * a) % m) / m;
};
};
export function fetchAPI(date) {
let result = [];
let dt = new Date(date);
let seed = dt.getDate();
let random = seededRandom(seed);
for (let i = 17; i <= 23; i++) {
if (random() < 0.5) {
result.push(i + ":00");
}
if (random() < 0.5) {
result.push(i + ":30");
}
}
return result;
}
export function submitAPI(formData) {
return true;
}
they created a fake API call, which returns random data.
The link provided by the course is broken, they might have moved it somewhere else. You should request your peers(they might have a common community or discussion board) to get an updated link.
And I think even the updated link will provide the same thing that this file returns.
an API is basically data, when you fetch something from an API it returns what it has stored.
In this case the API has two functions, one is to get the random data and other is to submit data.
If its really confusing at this point, you should ask someone in that community (coursera?) to provide the updated link. If you could just tell them it giving 404 error, they will know what to do.