# Navigating to API Path Using http\_request

**URL:** <https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241>\
**Category:** Developers\
**Created:** [February 3, 2024, 7:26am UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241 "2024-02-03T07:26:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![princess\_eth](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@princess\_eth](https://forum.dfinity.org/u/princess_eth)\
**Post date:** [February 3, 2024, 7:26am UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/1 "2024-02-03T07:26:58Z")

</div>

I am trying to build a REST API on ICP.

It seems that you can do this according to [Is it possible to build a REST API in a Canister?](https://forum.dfinity.org/t/is-it-possible-to-build-a-rest-api-in-a-canister/5355).

I am testing out the example that allows for an API call using a specific query path: [examples/motoko/http\_counter at master · dfinity/examples · GitHub](https://github.com/dfinity/examples/tree/master/motoko/http_counter).

In the code, in the `http_request`, if the path URL is ‘/stream’, then it returns a status, body, etc.

What is the full URL that I would use to navigate to /stream?

On local, I attempted but it returned a 404:

`http://[canisterId].localhost:4943/stream`

I see that when I test out the Candid UI, it is sending a request to:  
`http://127.0.0.1:4943/api/v2/canister/[canisterId]/query`

Any pointers would help. Thank you in advance!

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [February 3, 2024, 12:38pm UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/2 "2024-02-03T12:38:20Z")

</div>

If you call http\_request directly from candid ui you are going straight to the replica. If go want to pull the webpage from your browser you just use the url and the boundary node calls that query for you and pipes the result thru http.

Hard to say why you got a 404. Maybe it wasn’t deployed? Or wrong canister id? Did you get a response in candid ui?

---

<div class="post-metadata">

**Author:** ![princess\_eth](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@princess\_eth](https://forum.dfinity.org/u/princess_eth)\
**Post date:** [February 5, 2024, 6:16am UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/3 "2024-02-05T06:16:47Z")

</div>

Thank you so much for your response!

Here is my goal:

I would like to obtain a GET API with a standard endpoint. Ideally, I would like to access this endpoint using a format such as `http://[canisterId].localhost:4943/stream`.

After reviewing [HTTPS interface specification](https://internetcomputer.org/docs/current/references/ic-interface-spec/#http-interface), it looks like I can send a POST request `/api/v2/canister/<effective_canister_id>/query` with the function details in the body. I tried this but I was unable to get a result.

```auto
curl --location 'http://127.0.0.1:4943/api/v2/canister/br5f7-7uaaa-aaaaa-qaaca-cai/query' \

--header 'Content-Type: application/x-www-form-urlencoded' \

--data-urlencode 'method_name=http_request' \

--data-urlencode 'request_type=request' \

--data-urlencode 'canister_id=br5f7-7uaaa-aaaaa-qaaca-cai' \

--data-urlencode 'nonce=ba' \

--data-urlencode 'sender=aaaa' \

--data-urlencode 'ingress_expiry=1706993153000'

```

I assume this is what you mean by “pull the webpage from your browser you just use the url and the boundary node calls that query for you and pipes the result thru http.”

I’ll dig in more. Any feedback that you have would be appreciated!

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [February 5, 2024, 9:52am UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/4 "2024-02-05T09:52:14Z")

</div>

If `http://[canisterId].localhost:4943/stream` does not work, then maybe `http://localhost:4943/stream?canisterId=[canisterid]` works instead. But unless you’re using Safari both should work. You can see how we do it in CI with `curl` right [here](https://github.com/dfinity/sdk/blob/master/e2e/tests-dfx/assetscanister.bash#L171): `curl --fail -vv http://localhost:"$PORT"/new_file.txt?canisterId="$ID"`

The `/api/v2` endpoint is not what you want to use for a REST API that you talk to via HTTP. It’s meant for use with an [agent](https://internetcomputer.org/docs/current/tutorials/developer-journey/level-3/3.4-intro-to-agents/).

(Hopefully) stupid question: You’re deploying your canister to the local network, right? If you deploy to `--network ic` then you’d have to hit `<canister id>.icp0.io` instead

---

<div class="post-metadata">

**Author:** ![pu0238](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/pu0238/32/14831_2.png) [@pu0238](https://forum.dfinity.org/u/pu0238)\
**Post date:** [February 5, 2024, 12:42pm UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/5 "2024-02-05T12:42:10Z")

</div>

Hey, if you would like to build a REST API easily, you can always use one of the following HTTP routers:

Mokoto - [GitHub - krpeacock/server: Motoko Http Server (wip)](https://github.com/krpeacock/server)  
Rust - [GitHub - pu0238/pluto: HTTP framework designed for the needs of the internet computer network. When entering editing and updating data](https://github.com/pu0238/pluto)

---

<div class="post-metadata">

**Author:** ![princess\_eth](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@princess\_eth](https://forum.dfinity.org/u/princess_eth)\
**Post date:** [February 6, 2024, 1:46am UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/6 "2024-02-06T01:46:52Z")

</div>

Thank you so much for the suggestion. Is there any technical superiority in using these HTTP routers?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [February 6, 2024, 8:18am UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/7 "2024-02-06T08:18:13Z")

</div>

I don’t know about pluto, but with Motoko Server you don’t have to deal with certification yourself, which can be a big hassle

---

<div class="post-metadata">

**Author:** ![adrian-d-hidalgo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/adrian-d-hidalgo/32/13615_2.png) [@adrian-d-hidalgo](https://forum.dfinity.org/u/adrian-d-hidalgo)\
**Post date:** [February 6, 2024, 2:36pm UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/8 "2024-02-06T14:36:14Z")

</div>

Did you try using Azle? Azle recently released the possibility to build API Rest, try to start using this example: [https://github.com/demergent-labs/azle/tree/main/examples/express](https://github.com/demergent-labs/azle/tree/main/examples/express)

---

<div class="post-metadata">

**Author:** ![jdchibuk](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jdchibuk/32/13584_2.png) [@jdchibuk](https://forum.dfinity.org/u/jdchibuk)\
**Post date:** [February 6, 2024, 9:57pm UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/9 "2024-02-06T21:57:59Z")

</div>

@princess_eth

I managed to get a query response using [https://icp-api.io/api/v2/canister](https://icp-api.io/api/v2/canister)  
example built from mobile app using setup from [GitHub - kosta-bity/IcpKit: IcpKit.swift](https://github.com/kosta-bity/IcpKit)  
url format: **[https://icp-api.io/api/v2/canister/{CANISTER-ID}/query](https://icp-api.io/api/v2/canister/%7BCANISTER-ID%7D/query)**  
have yet to be able to get to submit data to a canister, only have been able to read a function that returns a Nat value

POST request data is sent with format “application/cbor”

> <https://github.com/kosta-bity/IcpKit/blob/main/Sources/IcpKit/Cryptography/ICPCBORSerialisation.swift>

http request builder:

> <https://github.com/kosta-bity/IcpKit/blob/main/Sources/IcpKit/ICPRequest/ICPRequest.swift>

hope this helps - still trying to figure this out myself

---

<div class="post-metadata">

**Author:** ![princess\_eth](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@princess\_eth](https://forum.dfinity.org/u/princess_eth)\
**Post date:** [February 6, 2024, 10:07pm UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/10 "2024-02-06T22:07:39Z")

</div>

Nice! As @Vivienne mentioned, you should avoid using `https://icp-api.io/api/v2/canister` as it is only meant for the agent to use.

Have you looked into using `http_response` function? Maybe @kosta, the founder of ICPKit, can provide more insight on how to do this on ICPKit.

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [February 6, 2024, 10:14pm UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/11 "2024-02-06T22:14:19Z")

</div>

This whole website is served off of Motoko server, and the greeting is handled via REST POST requests instead of an agent.

[https://qg33c-4aaaa-aaaab-qaica-cai.ic0.app/](https://qg33c-4aaaa-aaaab-qaica-cai.ic0.app/)

I also think that Azle with Express is going to be exciting, although I don’t think they’ve solved certification yet

---

<div class="post-metadata">

**Author:** ![princess\_eth](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@princess\_eth](https://forum.dfinity.org/u/princess_eth)\
**Post date:** [February 7, 2024, 6:07am UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/12 "2024-02-07T06:07:24Z")

</div>

Thank you. My code was perfectly fine but I was passing in the wrong canister Id the entire time. I figured out that I should have done `[id].localhost:4943/stream` instead of `[canisterId].localhost:4933/stream`.

I realized that the id refers to the canister id and canisterId refers to the Candid UI id. I asked another question about that here: [What is the difference between canisterId and id?](https://forum.dfinity.org/t/what-is-the-difference-between-canisterid-and-id/27373).

Hopefully, this helps another developer!

---

<div class="post-metadata">

**Author:** ![kosta](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@kosta](https://forum.dfinity.org/u/kosta)\
**Post date:** [January 24, 2026, 7:19am UTC](https://forum.dfinity.org/t/navigating-to-api-path-using-http-request/27241/13 "2026-01-24T07:19:58Z")

</div>

@Vivienne late response but : which url should be used then? I can update the IcpKit.swift
