百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

csv-to-api

> 编程语言
开源

概念验证:动态地从静态 CSV 生成 RESTful API

338 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

概念验证:动态地从静态 CSV 生成 RESTful API

CSV to API

Dynamically generate RESTful APIs from static CSVs. Provides JSON, XML, and HTML.

What Problem This Solves

The simplicity with which CSV files can be created has made them the default data format for bulk data. It is comparatively more difficult to create an API to share the same data atomically and transactionally.

How This Solves It

CSV to API acts as a filter, sitting between CSV and the browser, allowing users to interact with that CSV as if it was a native API. The column names (that is, the cells that comprise the first row in the file) function as the key names.

Note that this can be run on any server to create an API for any CSV file on any server. There is no need to install CSV to API for each unique CSV file or even each unique server—an organization can link to each and every one of their CSV files via CSV to API, or an individual could even use their own installation of CSV to API to access arbitrary remote CSV files as if they were APIs.

When Alternative PHP Cache (APC) is installed, parsed data is stored within APC, which accellerates its functionality substantially. While APC is not required, it is recommended highly.

Requirements

  • PHP
  • APC (optional)

Usage

  1. Copy class.csv-to-api.php and index.php to your web server.
  2. Load a CSV file via the URL index.php, using the arguments below.

Arguments

  • source: the URL to the source CSV
  • source_format: if the url does not end in .csv, you should specify 'csv' here (to facilitate future functionality)
  • format: the requested return format, either json, xml, or html (default json)
  • callback: if JSON, an optional JSONP callback
  • sort: field to sort by (optional)
  • sort_dir: direction to sort, either asc or desc (default asc)
  • any field(s): may pass any fields as a key/value pair to filter by
  • header_row: whether the source CSV has a header row; if missing, it will automatically assign field names (field_1, field_2, etc.); either n or y (default y)

Example Usage

All examples use data from REXUS, the primary tool used by the Public Building Service to track and manage the government's real property assets and to store inventory data, building data, customer data, and lease information.

Get CSV as JSONP (default behavior)

/csv-to-api/?source=http://www.gsa.gov/dg/data_gov_bldg_star.csv

Get results as XML

/csv-to-api/?source=http://www.gsa.gov/dg/data_gov_bldg_star.csv&format=xml

Get results as JSONP with a specified callback

/csv-to-api/?source=http://www.gsa.gov/dg/data_gov_bldg_star.csv&format=json&callback=parse_results

Get results as HTML

/csv-to-api/?source=http://www.gsa.gov/dg/data_gov_bldg_star.csv&format=html

Sort by a field

/csv-to-api/?source=http://www.gsa.gov/dg/data_gov_bldg_star.csv&sort=Bldg+Zip

Filter by a field

/csv-to-api/?source=http://www.gsa.gov/dg/data_gov_bldg_star.csv&Region+Code=11

License

GPLv3 or later.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言