Skip to content

Commit

Permalink
Merge pull request #21 from getAlby/task-readme
Browse files Browse the repository at this point in the history
chore: add README
  • Loading branch information
im-adithya authored Feb 27, 2024
2 parents f9584fa + 693862b commit d871fed
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SENTRY_DSN=
DATADOG_AGENT_URL=
PORT=8080
PORT=8080
DEFAULT_RELAY_URL=wss://relay.getalby.com/v1
DATABASE_URI=postgresql://user@localhost:5432/httpnostr
172 changes: 169 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,175 @@
# HTTP-Nostr API
# HTTP-Nostr

## Development
HTTP-Nostr is designed to bridge the gap between the decentralized Nostr protocol and traditional HTTP endpoints with NIP-47 in mind. It offers seamless integration, allowing for real-time interaction with the Nostr network through a well-defined HTTP API. Developers/Nostr clients can fetch NIP-47 info, publish NIP-47 requests, or subscribe to events based on filters to create client side applications on Nostr without worrying about websockets.

For subscriptions/NIP-47 requests, HTTP-Nostr accepts a webhook URL to notify about the new events/response event

<!-- ## 🛝 Try it out
Endpoints: -->

## 🤙 Usage

### Fetch NIP-47 Info

Returns Relay's NIP-47 capabilities.

<details>
<summary>
<code>GET</code> <code><b>/info</b></code>
</summary>

#### Parameters

> None
#### Response

> ```json
> {
> "id": "a16ye1391c22xx........xxxxx",
> "pubkey": "a16y69effexxxx........xxxxx",
> "created_at": 1708336682,
> "kind": 13194,
> "tags": [],
> "content": "pay_invoice,pay_keysend,get_balance,get_info,make_invoice,lookup_invoice,list_transactions",
> "sig": <signature>
> }
>```
</details>
------------------------------------------------------------------------------------------
### Publish NIP-47 Request
Returns the response event directly or to the Webhook URL if provided.
<details>
<summary>
<code>POST</code> <code><b>/nip47</b></code>
</summary>
#### Request Body
> | name | type | data type | description |
> |-----------|-----------|-------------------------|-----------------------------------------------------------------------|
> | relayUrl | optional | string | If no relay is provided, it uses the default relay |
> | webhookUrl | optional | string | Webhook URL to publish the response event, returns the event directly if not provided |
> | walletPubkey | required | string | Pubkey of the NIP-47 Wallet Provider |
> | event | required | JSON object ([nostr.Event](https://pkg.go.dev/github.com/nbd-wtf/[email protected]#Event)) | **Signed** request event |
#### Response (with webhook)
> "webhook received"
#### Response (without webhook)
> ```json
> {
> "id": "a16ycf4a01bcxx........xxxxx",
> "pubkey": "a16y69effexxxx........xxxxx",
> "created_at": 1709033612,
> "kind": 23195,
> "tags": [
> [
> "p",
> "f490f5xxxxx........xxxxx"
> ],
> [
> "e",
> "a41aefxxxxx........xxxxx"
> ]
> ],
> "content": <encrypted content>,
> "sig": <signature>
> }
>```
</details>
------------------------------------------------------------------------------------------
### Subscribe to Events
Notifies about new events matching the filter provided via webhooks
<details>
<summary>
<code>POST</code> <code><b>/subscribe</b></code>
</summary>
#### Request Body
> | name | type | data type | description |
> |-----------|-----------|-------------------------|-----------------------------------------------------------------------|
> | relayUrl | optional | string | If no relay is provided, it uses the default relay |
> | webhookUrl | required | string | Webhook URL to publish events |
> | filter | required | JSON object ([nostr.Filter](https://pkg.go.dev/github.com/nbd-wtf/[email protected]#Filter)) | Filters to subscribe to |
#### Response
> ```json
> {
> "subscription_id": 1,
> "webhookUrl": "https://your.webhook.url"
> }
>```
</details>
------------------------------------------------------------------------------------------
### Delete Subscriptions
Delete previously requested subscriptions.
<details>
<summary>
<code>DELETE</code> <code><b>/subscribe/:id</b></code>
</summary>
#### Parameter
> | name | type | data type | description |
> |-----------|-----------|-------------------------|-----------------------------------------------------------------------|
> | id | required | string | ID received on subscribing to a relay |
#### Response
> ```json
> "subscription x stopped"
>```
</details>
------------------------------------------------------------------------------------------
## 🚀 Installation
### Requirements
The application has no runtime dependencies. (simple Go executable).
As data storage PostgreSQL should be used.
$ cp .env.example .env
# edit the config for your needs
vim .env
## 🛠️ Development
`go run cmd/server/main.go`
## Configuration parameters
## ⚙️ Configuration parameters
- `PORT`: the port on which the app should listen on (default: 8080)
- `DEFAULT_RELAY_URL`: the relay the app should subscribe to if nothing is provided (default: "wss://relay.getalby.com/v1")
- `DATABASE_URI`: postgres connection string
## ⭐ Contributing
Contributions to HTTP-Nostr are welcome! Whether it's bug reports, feature requests, or contributions to code, please feel free to make your suggestions known.
## 📄 License
HTTP-Nostr is released under the MIT License. See the [LICENSE file](./LICENSE) for more details.
2 changes: 1 addition & 1 deletion internal/nostr/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
type Config struct {
SentryDSN string `envconfig:"SENTRY_DSN"`
DatadogAgentUrl string `envconfig:"DATADOG_AGENT_URL"`
DefaultRelayURL string `envconfig:"DEFAULT_RELAY_URL"`
DefaultRelayURL string `envconfig:"DEFAULT_RELAY_URL" default:"wss://relay.getalby.com/v1"`
DatabaseUri string `envconfig:"DATABASE_URI" default:"http-nostr.db"`
DatabaseMaxConns int `envconfig:"DATABASE_MAX_CONNS" default:"10"`
DatabaseMaxIdleConns int `envconfig:"DATABASE_MAX_IDLE_CONNS" default:"5"`
Expand Down

0 comments on commit d871fed

Please sign in to comment.