Skip to content

Instantly share code, notes, and snippets.

@Ajith-Pandian
Last active December 22, 2017 10:10
Show Gist options
  • Save Ajith-Pandian/935e43b795941113cdcebc14a5cdd720 to your computer and use it in GitHub Desktop.
Save Ajith-Pandian/935e43b795941113cdcebc14a5cdd720 to your computer and use it in GitHub Desktop.

Revisions

  1. Ajith-Pandian revised this gist Dec 22, 2017. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions Api.js
    Original file line number Diff line number Diff line change
    @@ -25,15 +25,13 @@ export default class Api {
    static request(route, params, verb) {
    const host = "http://10.0.2.2:3000/";//SERVER BASE URL
    const url = `${host}${route}`;
    console.log(url);
    let options = Object.assign(
    { method: verb },
    params ? { body: JSON.stringify(params) } : null
    );
    options.headers = Api.headers();
    return fetch(url, options)
    .then(response => response.json())
    .then(responseJson => responseJson)
    .catch(error => {
    console.error(error);
    });
  2. Ajith-Pandian created this gist Jul 13, 2017.
    41 changes: 41 additions & 0 deletions Api.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    export default class Api {
    static headers() {
    return {
    Accept: "application/json",
    "Content-Type": "application/json"
    };
    }

    static get(route) {
    return this.request(route, null, "GET");
    }

    static put(route, params) {
    return this.request(route, params, "PUT");
    }

    static post(route, params) {
    return this.request(route, params, "POST");
    }

    static delete(route, params) {
    return this.request(route, params, "DELETE");
    }

    static request(route, params, verb) {
    const host = "http://10.0.2.2:3000/";//SERVER BASE URL
    const url = `${host}${route}`;
    console.log(url);
    let options = Object.assign(
    { method: verb },
    params ? { body: JSON.stringify(params) } : null
    );
    options.headers = Api.headers();
    return fetch(url, options)
    .then(response => response.json())
    .then(responseJson => responseJson)
    .catch(error => {
    console.error(error);
    });
    }
    }