GithubHelp home page GithubHelp logo

csv-api's Introduction

csv-api

Mock API tool that reads from a CSV and generates a JSON API at runtime. Custom identifiers allow for querying specific rows, hidden columns, and mock HTTP errors.

Generated API

route description
/csv?url=... Returns an index based on all rows in the CSV at the url param
/csv?url=...&{field}={value} Returns 1 result where a row has a column {field} with value {value}. Only works on unique columns.
/healthcheck returns 'ok' if the API is up

Schema

Reserved Column Names

Reserved column names provide special utility and start with a $.

value description example
$http override http status, allows for forcing errors on entries 500

Identifier/Unique Columns

Columns names prefixed with an at-sign (@) can be used for lookups.

Example

@deviceId,name
1523,Roku 4K
1524,Apple TV
fetch("/csv?url=...&deviceId=1523"); // results for deviceId #1523
fetch("/csv?url=...&name=Apple%20TV"); // 404

Hidden Columns

Column names starting with a dollar sign ($) will never be returned. They are also used for reserved names, but can be used to embed any other data.

Shallow Columns

Fields by default will show up in the index (/csv). If you would like a field to only be available when requesting the individual ID prefix it with an exclamation point (!). The prefix is removed when the field is actually returned.

Example

@id,name,!age,$http
1,Alice,28,
2,Bob,26,404

When querying the /csv route without specifying an id, the API returns:

[
  {
    "id": "1",
    "name": "Alice"
  },
  {
    "id": "2",
    "name": "Bob"
  }
]

However, if an id is specified in the query, for example /csv?url=???&id=1, the API returns (note that the ! is stripped from the final field):

{
  "id": "1",
  "name": "Alice",
  "age": 28
}

csv-api's People

Contributors

sirajchokshi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.