Skip to content

Instantly share code, notes, and snippets.

@teimurjan
Last active May 21, 2018 06:10
Show Gist options
  • Save teimurjan/57eaea0ec7b89837d796a5d3b8fcf6b2 to your computer and use it in GitHub Desktop.
Save teimurjan/57eaea0ec7b89837d796a5d3b8fcf6b2 to your computer and use it in GitHub Desktop.
blog-digits-recognizer-python-flask-react-3
const validateStatusCode = response =>
new Promise((resolve, reject) => {
const status = response.status;
const next = status < 400 ? resolve : reject;
response.text().then(next);
});
export const makePrediction = image =>
fetch("/api/predict", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ image })
}).then(validateStatusCode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment