Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rtradeltd/swampi
swampi is a golang client for the ethereum swarm http api
https://github.com/rtradeltd/swampi
api client ethereum ethereum-swarm ethersphere golang http storage swarm
Last synced: 5 days ago
JSON representation
swampi is a golang client for the ethereum swarm http api
- Host: GitHub
- URL: https://github.com/rtradeltd/swampi
- Owner: RTradeLtd
- License: agpl-3.0
- Created: 2020-04-05T23:29:19.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-04-06T02:01:40.000Z (over 4 years ago)
- Last Synced: 2024-04-14T22:52:22.109Z (7 months ago)
- Topics: api, client, ethereum, ethereum-swarm, ethersphere, golang, http, storage, swarm
- Language: Go
- Size: 16.7 MB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# swampi
`swampi` is a golang client for the swarm http api, and enables programmatic access to the swarm API via your golang programs. It's primary purpose is for use with Temporal, but other users may find it useful.
# format
Individual API calls are represented by a typed string call `APICall`. This allows reducing code surface for common task such as request handling, request formatting, etc..
The value of `APICall` instances is the actual HTTP path for the API call. For example single file upload is stored in code as `APICall("/bzz:/")`, so `APICall::String` will return the http path to be fed into `http.NewRequest`. Additionally methods like `APICall::ContentType` mean you don't have to deal with guessing the content type for requests as its done for you. Additionally certain API calls require url arguments, such as the single file download which takes the swarm hash. These are handled with `APICall::ParseArgs`.
# usage
For more detailed usage instructions see the tests, but in essence it consists of:
```Golang
// this creates our swampi client
swampi := New("http://localhost:8500")
fileBytes, err := ioutil.ReadFile(tt.args.filePath)
if err != nil {
log.Fatal(err)
}
// handles parsing the api calls and sending it, returning the response
resp, err := swampi.Send(SingleFileUpload, bytes.NewReader(fileBytes), map[string][]string{
"content-type": []string{SingleFileUpload.ContentType()},
})
if err != nil {
log.Fatal(err)
}
// do stuff with response
```