Comments (4)
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.
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.
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.
@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)
- decompressGzippedContent : missing return when rejecting promise HOT 2
- How to reuse cookie in HttpClient HOT 1
- Sending body with delete request HOT 3
- Underscore 1.12.1 being used shows vulnerability https://npmjs.com/advisories/1674
- Possible regression in proxy variable processing HOT 4
- SyntaxError: Invalid regular expression: invalid group specifier name HOT 3
- Confusing deprecation: "1.8.5 contains changes that are not compatible with Node 6" HOT 3
- Update Azure pipeline and remove GitHub action HOT 2
- Authentication header is set on redirect request HOT 1
- ETIMEDOUT for certain calls on Node 16 HOT 5
- Performance issues with readBody in HttpClient.ts HOT 3
- error from zlib not handled properly in decompressGzippedContent() HOT 4
- This repo is missing important files
- Unable to read error message from response header HOT 3
- uncaught reference error: the process does not define in browser HOT 11
- not working with react with next js , HOT 3
- Discussion: use with fetch API HOT 5
- Incorrect header check error while decompressing a response HOT 2
- Chrome 113 breaks typed-rest-client HOT 3
- Please tag released versions HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typed-rest-client.