Giter Club home page Giter Club logo

Comments (4)

etiago avatar etiago commented on July 17, 2024

I really like the idea behind typed-rest-client but as it stands it makes it unusable for a backend+frontend combo unless I hardcode the host where my application is running (which can vary per deployment). Ideally I would like an HTTP client which will just take the current host and pick it up from there when using relative paths.

from typed-rest-client.

stephenmichaelf avatar stephenmichaelf commented on July 17, 2024

Thanks for reaching out about this!

I want to make sure I understand: you are saying when you have the library running on a machine you want it to use the url of the machine it's running on as the base if you don't pass one in? So it can call in to itself? Can't you dynamically get the URL at runtime and set it before you make your request? Or if you want you could do a PR with the change :)

from typed-rest-client.

etiago avatar etiago commented on July 17, 2024

Now I realize I didn't explain the problem I'm getting as well as I thought I did...!

The issue is specific to running the library as part of an application running in the browser. Specifically I'm seeing it in the context of a React application. I think this is relevant because when running in the browser, if I'm sending a request to /products, I expect it to go to <WHATEVER_DOMAIN_THE_WEBSITE_IS_BEING_ACCESSED_ON_USING_WHATEVER_PROTOCOL_ON_WHATEVER_PORT>/products. With an example, if I'm visiting https://www.freshfruit.com/ and if within the JS I make a request to /products, I expect the request to go to https://www.freshfruit.com/products.

This behavior is likely to be different in a Node backend application as then there's no implicit baseUrl such as the one in the browser.

Nonetheless, I've submitted a pull request with a change that fixes my issue. The existing tests also all currently pass. If we're happy with the change, I would also like to write a couple more tests to go with it (and I will need to sort out a CLA first as I'm not sure my employer contractually currently allows me to share any code publicly).

from typed-rest-client.

alvaroc1 avatar alvaroc1 commented on July 17, 2024

@etiago Why not use the following?

new rc.RestClient('frontend', window.location.protocol + "//" + window.location.host);

I personally prefer it explicit.

from typed-rest-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.