Skip to content

Instantly share code, notes, and snippets.

@shahzadns
Last active October 14, 2017 02:46
Show Gist options
  • Select an option

  • Save shahzadns/cf37c2a8edc2612820219a0430565fa1 to your computer and use it in GitHub Desktop.

Select an option

Save shahzadns/cf37c2a8edc2612820219a0430565fa1 to your computer and use it in GitHub Desktop.

Revisions

  1. shahzadns revised this gist Oct 14, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions REST APIs response format
    Original file line number Diff line number Diff line change
    @@ -19,12 +19,12 @@ var res = {
    // client-side - 400 (payload missing), 401(invalid payload), 403 (unauthorized),
    // server-side - 500 (internal error - script code breaks), 503 (service unavailable - server is down)
    var res = {
    code: 'ESU1', //Error Sign Up - email already exist, and similar stuff. (FE will map the given error)
    code: 'ESU1', //Error Sign Up - email already exist, and similar stuff. (FE should map the given error)
    messages: ['sign-up failed', 'email exists']
    };

    // upload excel file error example - or any similar stuff that can have multiple errors (other example. BE validation)
    var res = {
    code: 'ERU1', //Error Records Upload - partial success - (FE will map the given error)
    code: 'ERU1', //Error Records Upload - partial success - (FE should map the given error)
    messages: ['line#54 failed', 'line#63 failed', 'line#100 failed']
    };
  2. shahzadns revised this gist Oct 14, 2017. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions REST APIs response format
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,11 @@

    /**
    * Created on: Oct 14 2017
    * Created by: Shahzad Nawaz
    * Derived from different sources, Stakoverflow, Blogs, experience.
    * For more advanced handling - checkout https://github.com/adnan-kamili/rest-api-response-format
    */

    // success response example - http status code - always 200
    var res = {
    code: '200',
  3. shahzadns revised this gist Oct 14, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions REST APIs response format
    Original file line number Diff line number Diff line change
    @@ -11,12 +11,12 @@ var res = {
    // client-side - 400 (payload missing), 401(invalid payload), 403 (unauthorized),
    // server-side - 500 (internal error - script code breaks), 503 (service unavailable - server is down)
    var res = {
    code: 'ESU1', //Error Sign Up - email already exist, and similar stuff.
    code: 'ESU1', //Error Sign Up - email already exist, and similar stuff. (FE will map the given error)
    messages: ['sign-up failed', 'email exists']
    };

    // upload excel file error example - or any similar stuff that can have multiple errors (other example. BE validation)
    var res = {
    code: 'ERU1', //Error Records Upload - partial success
    code: 'ERU1', //Error Records Upload - partial success - (FE will map the given error)
    messages: ['line#54 failed', 'line#63 failed', 'line#100 failed']
    };
  4. shahzadns created this gist Oct 14, 2017.
    22 changes: 22 additions & 0 deletions REST APIs response format
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    // success response example - http status code - always 200
    var res = {
    code: '200',
    messages: ['signup success'],
    data: {
    user: user
    }
    };

    // error response example - http status code -
    // client-side - 400 (payload missing), 401(invalid payload), 403 (unauthorized),
    // server-side - 500 (internal error - script code breaks), 503 (service unavailable - server is down)
    var res = {
    code: 'ESU1', //Error Sign Up - email already exist, and similar stuff.
    messages: ['sign-up failed', 'email exists']
    };

    // upload excel file error example - or any similar stuff that can have multiple errors (other example. BE validation)
    var res = {
    code: 'ERU1', //Error Records Upload - partial success
    messages: ['line#54 failed', 'line#63 failed', 'line#100 failed']
    };