Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aibtcdev/gated-402-api
Example API implementation with HTTP 402 responses for unpaid resources.
https://github.com/aibtcdev/gated-402-api
Last synced: 19 days ago
JSON representation
Example API implementation with HTTP 402 responses for unpaid resources.
- Host: GitHub
- URL: https://github.com/aibtcdev/gated-402-api
- Owner: aibtcdev
- Created: 2024-01-25T18:26:06.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-08-01T00:30:15.000Z (5 months ago)
- Last Synced: 2024-08-01T03:27:16.945Z (5 months ago)
- Language: TypeScript
- Homepage: https://api.aibtc.dev
- Size: 153 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome_ai_agents - Gated 402 API - An API using a Stacks smart contract to control access, issuing a 200 status for access approval and a 402 with payment instructions for denial [github](https://github.com/aibtcdev/gated-402-api) | [github profile](https://github.com/aibtcdev) | [website](https://aibtc.dev/) | [discord](https://discord.gg/5DJaBrf) (Learning / Repositories)
- awesome_ai_agents - Gated 402 API - An API using a Stacks smart contract to control access, issuing a 200 status for access approval and a 402 with payment instructions for denial [github](https://github.com/aibtcdev/gated-402-api) | [github profile](https://github.com/aibtcdev) | [website](https://aibtc.dev/) | [discord](https://discord.gg/5DJaBrf) (Learning / Repositories)
README
# AIBTC Gated 402 API
## Description
This is a simple API that uses a Stacks smart contract to verify access to a resource.
If the user has access, the API returns a 200 status code.
If the user does not have access, the API returns a 402 status code with instructions to pay the invoice.
## Example Endpoint
URL: `/bitcoin-face`
Requires header: `X-Stacks-SignedMessageData`
- data to be signed is the requesting Stacks address as a string
- data passed in header should be the string returned by signing structured data with @stacks/transactions
- helper script defines domain, message format, and returns signed dataQuery parameters:
- address (req): the Stacks address requesting the resource
- resource (req): the name of the resource in the smart contract
- network (opt): the Stacks network to return data from ("mainnet" or "testnet", default: "testnet")Example with curl for local development:
```bash
curl -X GET -H "X-Stacks-SignedMessageData: 424b7c7d4faf0dc3edb5e3ce686341621e9305fdd00434dd15a1254a9ce3a60d3ed5def54e9d588a1d12e499411c42af8f897c497aeb5ff4566cec18afc0052500" "http://localhost:8787/bitcoin-face?resource=bitcoin-face&address=ST2HQ5J6RP8HSQE9KKGWCHW9PT9SVE4TDGBZQ3EKR"
```Example with curl with hosted API:
```bash
curl -X GET -H "X-Stacks-SignedMessageData: 424b7c7d4faf0dc3edb5e3ce686341621e9305fdd00434dd15a1254a9ce3a60d3ed5def54e9d588a1d12e499411c42af8f897c497aeb5ff4566cec18afc0052500" "https://api.aibtc.dev/bitcoin-face?resource=bitcoin-face&address=ST2HQ5J6RP8HSQE9KKGWCHW9PT9SVE4TDGBZQ3EKR"
```## Development
Tech stack:
- Wrangler
- Hono
- Stacks.jsTo run this locally:
1. Clone repository
2. Install dependencies: `npm install`
3. Run locally: `npm start`Deployments are handled by Wrangler and Cloudflare Workers.