Skip to content

Instantly share code, notes, and snippets.

@mirsahib
Last active December 20, 2021 05:05
Show Gist options
  • Save mirsahib/ee953c17c5484ed6da261f05e6f1bd0f to your computer and use it in GitHub Desktop.
Save mirsahib/ee953c17c5484ed6da261f05e6f1bd0f to your computer and use it in GitHub Desktop.

Revisions

  1. mirsahib revised this gist Dec 20, 2021. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions api.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@

    // createUser and readUser is only necessary for signup and sign in page
    const createUser = async (url, data) => {
    try {
    let response = await fetch(url, {
    @@ -14,6 +14,7 @@ const createUser = async (url, data) => {
    console.log(err);
    }
    }

    const readUser = async (url, data) => {
    try {
    let response = await fetch(url+'?email='+data.email+'&password='+data.password, {
    @@ -28,7 +29,7 @@ const readUser = async (url, data) => {
    console.log(err);
    }
    }

    //upload image with label data to realm
    const uploadData = async (url, data) => {
    try {
    let response = await fetch(url, {
    @@ -44,10 +45,10 @@ const uploadData = async (url, data) => {
    console.log(err);
    }
    }

    //upload image to cloudinary
    const uploadImage = async (url, uri) => {
    try {
    let base64Img = `data:image/jpg;base64,${uri}`
    let base64Img = `data:image/jpg;base64,${uri}`//attach base64 image
    let imageData = { file: base64Img, upload_preset: "annotationImage" }
    let response = await fetch(url, {
    method: "POST",
  2. mirsahib created this gist Dec 19, 2021.
    72 changes: 72 additions & 0 deletions api.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@

    const createUser = async (url, data) => {
    try {
    let response = await fetch(url, {
    method: "POST",
    headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
    },
    body: JSON.stringify(data),
    });
    return await response.json();
    } catch (err) {
    console.log(err);
    }
    }
    const readUser = async (url, data) => {
    try {
    let response = await fetch(url+'?email='+data.email+'&password='+data.password, {
    method: "GET",
    headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
    },
    });
    return await response.json();
    } catch (err) {
    console.log(err);
    }
    }

    const uploadData = async (url, data) => {
    try {
    let response = await fetch(url, {
    method: "POST",
    headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
    },
    body: JSON.stringify(data),
    });
    return await response.json();
    } catch (err) {
    console.log(err);
    }
    }

    const uploadImage = async (url, uri) => {
    try {
    let base64Img = `data:image/jpg;base64,${uri}`
    let imageData = { file: base64Img, upload_preset: "annotationImage" }
    let response = await fetch(url, {
    method: "POST",
    headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
    },
    body: JSON.stringify(imageData),
    });
    return await response.json();
    } catch (err) {
    console.log(err);
    }
    }


    export {
    createUser,
    readUser,
    uploadData,
    uploadImage
    }