neandertech / smithy4s-fetch

Smithy4s client directly using Fetch APIs, without bringing http4s/cats, to dramatically reduce bundle size
9 stars 1 forks source link

Double slash if the base URI has a path #2

Closed kubukoz closed 1 week ago

kubukoz commented 1 week ago

To reproduce:

//> using dep "tech.neander::smithy4s-deriving::0.0.2"
//> using dep tech.neander::smithy4s-fetch::0.0.3
//> using platform scala-js
//> using scala 3.4.2
//> using option -Wunused:all

import smithy4s.*

import scala.annotation.experimental
import scala.scalajs.js.Promise

import deriving.given
import deriving.*
import aliases.*
import smithy4s_fetch.SimpleRestJsonFetchClient

@experimental
trait HttpbinService derives API:

  @readonly
  @httpGet("/get")
  def get(): Promise[Document]

@main @experimental
def helloWorld =
  val service: HttpbinService =
    SimpleRestJsonFetchClient(
      API.service[HttpbinService],
      "https://httpbin.org/api",
    ).make.unliftService

  service.get().`then`(v => println(v))
<!DOCTYPE html>

<html>
  <head>
    <script src="./helloWorld.js" type="text/javascript"></script>
  </head>
</html>

Open the HTML file, see network tab in the browser, look for the request path.

keynmol commented 1 week ago

Isn't this a carnal sin of Smithy4s to use relative URLs in endpoint definitions? :P

Anyways, should be an easy fix - let me know if you want to do this, or I'll do it myself in a couple of days

kubukoz commented 1 week ago

Isn't this a carnal sin of Smithy4s to use relative URLs in endpoint definitions? :P

I'm using Vite as a proxy to the backend so I don't have to enable CORS, in the real app it'll probably be proxied as well - but the "actual" backend doesn't have the prefix 😅

kubukoz commented 1 week ago

I'm looking into this.