adding basic comments to rest api

This commit is contained in:
Dmitriy Ryajov 2022-01-10 13:17:18 -06:00
parent fbe161a073
commit d7fca0bdbe
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
1 changed files with 19 additions and 1 deletions

View File

@ -61,6 +61,14 @@ proc initRestApi*(node: DaggerNodeRef): RestRouter =
"/api/dagger/v1/connect/{peerId}") do (
peerId: PeerID,
addrs: seq[MultiAddress]) -> RestApiResponse:
## Connect to a peer
##
## If `addrs` param is supplied, it will be used to
## dial the peer, otherwise the `peerId` is used
## to invoke peer discovery, if it successedes
## the returned addresses will be used to dial
##
if peerId.isErr:
return RestApiResponse.error(
Http400,
@ -86,6 +94,10 @@ proc initRestApi*(node: DaggerNodeRef): RestRouter =
MethodGet,
"/api/dagger/v1/download/{id}") do (
id: Cid, resp: HttpResponseRef) -> RestApiResponse:
## Download a file from the node in a streaming
## manner
##
if id.isErr:
return RestApiResponse.error(
Http400,
@ -126,13 +138,16 @@ proc initRestApi*(node: DaggerNodeRef): RestRouter =
MethodPost,
"/api/dagger/v1/upload") do (
) -> RestApiResponse:
## Upload a file in a streamming manner
##
trace "Handling file upload"
var bodyReader = request.getBodyReader()
if bodyReader.isErr():
return RestApiResponse.error(Http500)
# Attempt to handle `Expect` header
# some clients (curl), waits 1000ms
# some clients (curl), wait 1000ms
# before giving up
#
await request.handleExpect()
@ -179,6 +194,9 @@ proc initRestApi*(node: DaggerNodeRef): RestRouter =
router.api(
MethodGet,
"/api/dagger/v1/info") do () -> RestApiResponse:
## Print rudimentary node information
##
var addrs: string
for a in node.switch.peerInfo.addrs:
addrs &= "- " & $a & "\n"