Skip to content

API Design

Samyoga Bhattarai edited this page Jul 6, 2021 · 30 revisions

Download

POST /api/v1/download/

Parameters:

"area_of_interest": "businesses" or "workforce"
"type": "Impact" or "Need" or "Outlook" or "Preparedness"
"survey_question": ""

Sample response:
{
  "message": "Successfully fetched",
  "code": 200,
  "csv_link": "_____.csv"
}

Stories

GET /api/v1/stories/

Parameters:

limit: 20
page_number: 1

Sample response:
{
  "message": "Successfully fetched",
  "code": 200,
  "data": [
    {
      "id": "",
      "category": "economy",
      "title": "",
      "writer": "",
      "created_at": "",
      "image": "",
      "article" : "",
    },
    {
      "id": "",
      "category": "social",
      "title": "",
      "writer": "",
      "created_at": "",
      "image": "",
      "article" : "",
    }
  ]
}

GET /api/v1/stories/{id}

Sample response:
{
  "message": "Successfully fetched",
  "code": 200,
  "data": {
    "title": "",
    "writer": "",
    "created_at": "",
    "image": "",
    "image_caption": "",
    "article": ""
  }
}

Visualization

GET /api/v1/viz/heatmap/businesses

Parameters and values:
  1. var_group can take the following values: impact, preparednes,
Sample response
{
  "message": "Successfully fetched",
  "code": 200,
  "data": {
    "highlights": [
      {
        "variablename": "revenue_category",
        "variablegroup": "impact",
        "label": {
          "en": "Revenues for most of the businesses is almost zero",
          "ne": "धेरै जसो ब्यापारका लागि राजस्व शून्य छ"
        }
      },
      {
        "variablename": "employment_category",
        "variablegroup": "outlook",
        "label": {
          "en": "Around 95% businesses shut down, among them 17% will never open again",
          "ne": "लगभग 95% व्यवसायहरू बन्द भए, ती मध्ये 17% फेरि कहिले पनि खून्य छ"
        }
      }
    ],
    "distribution": {
      "revenue_category": [
        {
          "label": {
            "en": "None or insignificant impact",
            "ne": ""
          },
          "total": "",
          "perc_of_total": "",
          "geometries": {
            "features": [
              {
                "businessname": "Himalayan restaurant",
                "businesstype": "Restaurant and Bar",
                "geometry": {
                  "type": "Point",
                  "coordinates": [
                    [
                      4.446657,
                      51.02457
                    ]
                  ]
                }
              },
              {
                "businessname": "Himalayan restaurant",
                "businesstype": "Restaurant and Bar",
                "geometry": {
                  "type": "Point",
                  "coordinates": [
                    [
                      4.446657,
                      51.02457
                    ]
                  ]
                }
              }
            ]
          }
        },
        {
          "label": "Revenue for 2020 was below 25% of 2019",
          "total": "",
          "perc_of_total": "",
          "geometries": {
            "features": [
              {
                "businessname": "Himalayan restaurant",
                "businesstype": "Restaurant and Bar",
                "geometry": {
                  "type": "Point",
                  "coordinates": [
                    [
                      4.446657,
                      51.02457
                    ]
                  ]
                }
              },
              {
                "businessname": "Himalayan restaurant",
                "businesstype": "Restaurant and Bar",
                "geometry": {
                  "type": "Point",
                  "coordinates": [
                    [
                      4.446657,
                      51.02457
                    ]
                  ]
                }
              }
            ]
          }
        }
      ],
      "employment_category": [
        {
          "label": "",
          "total": "",
          "perc_of_total": "",
          "geometries": {
            "features": [
              {
                "businessname": "Himalayan restaurant",
                "businesstype": "Restaurant and Bar",
                "geometry": {
                  "type": "Point",
                  "coordinates": [
                    [
                      4.446657,
                      51.02457
                    ]
                  ]
                }
              },
              {
                "businessname": "Himalayan restaurant",
                "businesstype": "Restaurant and Bar",
                "geometry": {
                  "type": "Point",
                  "coordinates": [
                    [
                      4.446657,
                      51.02457
                    ]
                  ]
                }
              }
            ]
          }
        },
        {
          "label": "",
          "total": "",
          "perc_of_total": "",
          "geometries": {
            "features": [
              {
                "businessname": "Himalayan restaurant",
                "businesstype": "Restaurant and Bar",
                "geometry": {
                  "type": "Point",
                  "coordinates": [
                    [
                      4.446657,
                      51.02457
                    ]
                  ]
                }
              },
              {
                "businessname": "Himalayan restaurant",
                "businesstype": "Restaurant and Bar",
                "geometry": {
                  "type": "Point",
                  "coordinates": [
                    [
                      4.446657,
                      51.02457
                    ]
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

GET /api/v1/viz/distributions?survey=workers&var_group=impact

Parameters and values:
  1. survey can take the following values: workers, businesses
  2. var_group can take the following values: impact, preparednes, outlook, need
Notes

This was previously /viz/workers/univariate.

Sample response
{
  "message": "Successfully fetched",
  "code": 200,
  "data": [
    {
      "variable": "b_has_loan",
      "title": {
        "en": "Do you have any outstanding loans?",
        "ne": ""
      },
      "asked_condition": "general",
      "asked_total": "110",
      "dist": [
        {
          "label": {
            "en": "No",
            "ne": ""
          },
          "total": "",
          "perc_of_total": ""
        },
        {
          "label": {
            "en": "No",
            "ne": ""
          },
          "total": "",
          "perc_of_total": ""
        }
      ]
    },
    {
      "variable": "i_lost_job",
      "title": {
        "en": "Did you lose your job during the pandemic?",
        "ne": ""
      },
      "asked_condition": "general",
      "asked_total": "110",
      "dist": [
        {
          "label": {
            "en": "Yes",
            "ne": ""
          },
          "total": "",
          "perc_of_total": ""
        },
        {
          "label": {
            "en": "No",
            "ne": ""
          },
          "total": "",
          "perc_of_total": ""
        }
      ]
    }
  ]
}

GET /api/v1/viz/relationships?survey=workers&var_group=impact&dimension=gender

Parameters and values:
  1. survey can take the following values: workers, businesses
  2. var_group can take the following values: impact, preparednes,
  3. dimension can take the following values: gender, edu_levl,
Notes

This was previously /viz/workers/bivariate.

Sample response
{
  "message": "Successfully fetched",
  "code": 200,
  "data": {
    "univariate": [
      {
        variable: "m_gender",
        varable_label_en: "Do you have any outstanding loans", // maybe not needed if metadata available
        variable_label_ne: "",
        dist: [
          {
            label_ne: "",
            label_en: "Male",
            total: "",
            perc_of_total: "",
          },
          {
            label_ne: "",
            label_en: "Female",
            total: "",
            perc_of_total: "",
          },
          {
            label_ne: "",
            label_en: "Third gendder",
            total: "",
            perc_of_total: "",
          },
        ],
      },
    ],
    "bivariate": [
      {
        "title_en": "",
        "title_ne": "",
        "chart_data": [
          {
            "y_label_en": "",
            "y_label_ne": "",
            "total": "",
            "perc_of_total": "",
            "dist": [
              {
                "x_label_en": "",
                "x_label_ne": "",
                "total": "",
                "perc_of_total": ""
              },
              {
                "x_label_en": "",
                "x_label_ne": "",
                "total": "",
                "perc_of_total": ""
              },
              {
                "x_label_en": "",
                "x_label_ne": "",
                "total": "",
                "perc_of_total": ""
              }
            ]
          },
          {
            "y_label_en": "",
            "y_label_ne": "",
            "total": "",
            "perc_of_total": "",
            "dist": [
              {
                "x_label_en": "",
                "x_label_ne": "",
                "total": "",
                "perc_of_total": ""
              },
              {
                "x_label_en": "",
                "x_label_ne": "",
                "total": "",
                "perc_of_total": ""
              },
              {
                "x_label_en": "",
                "x_label_ne": "",
                "total": "",
                "perc_of_total": ""
              }
            ]
          }
        ]
      }
    ]
  }
}