survos/nara-php-api
Composer 安装命令:
composer require survos/nara-php-api
包简介
PHP client for NARA's Catalog API v2
README 文档
README
A PHP client for the National Archives Catalog API v2.
Installation
composer require survos/nara-php-api
This library requires Symfony HTTP Client (included as a dependency).
Quick Start
use Survos\Nara\ClientFactory; $client = ClientFactory::create($yourApiKey); // Search records (raw array response) $results = $client->search(['q' => 'constitution']); echo $results['body']['hits']['total']['value']; // Search with typed DTOs $results = $client->searchWithDtos(['q' => 'constitution']); foreach ($results as $result) { echo $result->record->title; echo $result->record->naId; } // Search transcriptions $transcriptions = $client->transcriptionsSearchWithDtos(['q' => 'constitution']); foreach ($transcriptions as $t) { echo $t->contribution; } // Get single record by NA ID $record = $client->getRecordByNaId(1667751); echo $record->title;
Contributing data (write)
The Catalog API can also write contributions — transcriptions, tags, and comments — back to the National Archives. This is how you give OCR or human-keyed text a permanent home in the national record.
use Survos\Nara\ClientFactory; // Writes need your API key *and* your Catalog user UUID (the contribution // is attributed to that account). Set it once on the client... $client = ClientFactory::create($yourApiKey, userId: $yourCatalogUuid); // Submit the full text of a digital object as a transcription. // Re-submitting overwrites the record's transcription (NARA keeps history). $result = $client->submitTranscription(naId: 12345, transcription: $ocrText); if ($result->success) { echo "Saved as contribution {$result->contributionId}"; } else { // 401/422 etc. are returned (not thrown) so a bulk loop can log & continue. echo "Failed (HTTP {$result->statusCode}): {$result->message}"; } // Tags and comments work the same way: $client->submitTag(521451, 'president'); $client->submitComment(521451, 'This photo also appears in series ...'); // Or pass the user UUID per call instead of on the client: $client->submitTranscription(12345, $ocrText, userId: $someOtherUuid);
These map to POST /api/v2/{transcriptions,tags,comments}/ with a JSON body of
{ <text field>, targetNaId, userId }.
Enabling write access
Write access is not enabled on a standard read key. Email
Catalog_API@nara.gov with your email and Catalog
username to have contributions enabled for your key. You also need your Catalog
user UUID — find it in the userId field of any of your existing
contributions (e.g. GET /api/v2/contributions/search).
CLI: bin/contribute.php
A safe demo command — dry-run by default, it only writes when you pass --force:
export NARA_API_KEY="your-key" export NARA_USER_ID="your-catalog-uuid" # Preview exactly what would be sent (no write): php bin/contribute.php transcription 12345 --text "Dear Sir, ..." # Read the text from a file: php bin/contribute.php transcription 12345 --text-file page1.txt # Pipe OCR output straight in, then actually submit: mistral-ocr page1.png | php bin/contribute.php transcription 12345 --force
API Key
To get an API key, email Catalog_API@nara.gov.
Demo
A CLI demo is included:
# Using environment variable export NARA_API_KEY="your-key" php bin/search.php search "constitution" # Using --api-key option php bin/search.php search "constitution" --api-key=your-key php bin/search.php search "presidents" --limit=5 # Lookup by NA ID php bin/search.php search 1667751 # Verbose output php bin/search.php search "constitution" -vvv --limit=1
Bulk Data
For large-scale data access, NARA provides bulk downloads on AWS S3:
# Download full descriptions (87 GB) aws s3 cp s3://nara-national-archives-catalog/zip/nac_export_descriptions_2025-04-08.zip ./ --no-sign-request # Sync specific record group aws s3 sync s3://nara-national-archives-catalog/descriptions/record-groups/rg_011/ ./rg011/ --no-sign-request
See NARA Developer Docs for more.
License
MIT License - see LICENSE file.
survos/nara-php-api 适用场景与选型建议
survos/nara-php-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「catalog」 「client」 「sdk」 「archives」 「swagger」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 survos/nara-php-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 survos/nara-php-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 survos/nara-php-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Extension for Catalog Manager.
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
统计信息
- 总下载量: 58
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 39
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-31