adding basic comments to rest api
This commit is contained in:
parent
fbe161a073
commit
d7fca0bdbe
|
@ -61,6 +61,14 @@ proc initRestApi*(node: DaggerNodeRef): RestRouter =
|
||||||
"/api/dagger/v1/connect/{peerId}") do (
|
"/api/dagger/v1/connect/{peerId}") do (
|
||||||
peerId: PeerID,
|
peerId: PeerID,
|
||||||
addrs: seq[MultiAddress]) -> RestApiResponse:
|
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:
|
if peerId.isErr:
|
||||||
return RestApiResponse.error(
|
return RestApiResponse.error(
|
||||||
Http400,
|
Http400,
|
||||||
|
@ -86,6 +94,10 @@ proc initRestApi*(node: DaggerNodeRef): RestRouter =
|
||||||
MethodGet,
|
MethodGet,
|
||||||
"/api/dagger/v1/download/{id}") do (
|
"/api/dagger/v1/download/{id}") do (
|
||||||
id: Cid, resp: HttpResponseRef) -> RestApiResponse:
|
id: Cid, resp: HttpResponseRef) -> RestApiResponse:
|
||||||
|
## Download a file from the node in a streaming
|
||||||
|
## manner
|
||||||
|
##
|
||||||
|
|
||||||
if id.isErr:
|
if id.isErr:
|
||||||
return RestApiResponse.error(
|
return RestApiResponse.error(
|
||||||
Http400,
|
Http400,
|
||||||
|
@ -126,13 +138,16 @@ proc initRestApi*(node: DaggerNodeRef): RestRouter =
|
||||||
MethodPost,
|
MethodPost,
|
||||||
"/api/dagger/v1/upload") do (
|
"/api/dagger/v1/upload") do (
|
||||||
) -> RestApiResponse:
|
) -> RestApiResponse:
|
||||||
|
## Upload a file in a streamming manner
|
||||||
|
##
|
||||||
|
|
||||||
trace "Handling file upload"
|
trace "Handling file upload"
|
||||||
var bodyReader = request.getBodyReader()
|
var bodyReader = request.getBodyReader()
|
||||||
if bodyReader.isErr():
|
if bodyReader.isErr():
|
||||||
return RestApiResponse.error(Http500)
|
return RestApiResponse.error(Http500)
|
||||||
|
|
||||||
# Attempt to handle `Expect` header
|
# Attempt to handle `Expect` header
|
||||||
# some clients (curl), waits 1000ms
|
# some clients (curl), wait 1000ms
|
||||||
# before giving up
|
# before giving up
|
||||||
#
|
#
|
||||||
await request.handleExpect()
|
await request.handleExpect()
|
||||||
|
@ -179,6 +194,9 @@ proc initRestApi*(node: DaggerNodeRef): RestRouter =
|
||||||
router.api(
|
router.api(
|
||||||
MethodGet,
|
MethodGet,
|
||||||
"/api/dagger/v1/info") do () -> RestApiResponse:
|
"/api/dagger/v1/info") do () -> RestApiResponse:
|
||||||
|
## Print rudimentary node information
|
||||||
|
##
|
||||||
|
|
||||||
var addrs: string
|
var addrs: string
|
||||||
for a in node.switch.peerInfo.addrs:
|
for a in node.switch.peerInfo.addrs:
|
||||||
addrs &= "- " & $a & "\n"
|
addrs &= "- " & $a & "\n"
|
||||||
|
|
Loading…
Reference in New Issue