Closed CodeSandwich closed 11 months ago
I agree, happy to accept a PR for this.
Do you think that it would be beneficial to keep the existing Node
's host
, port
, path
and protocol
fields? I think not, just having a single url
field should be enough, but this will be a breaking change.
We should not break backward compatibility so this should be an additional way to construct Node.
Description
To create an instance of
Node
the user need to provide a host, a port, a path and a protocol. These parameters are then used to build the URL in functionurl
, which seems to be the only usage of these 4 parameters.It would be more convenient if it was possible to pass the URL directly into the
Node
constructor instead of breaking it up into 4 ingredients passed as separate variables. This would help downstream projects handle configuration in a more concise way. For exampledocsearch-scraper
requires users to passTYPESENSE_HOST
,TYPESENSE_PORT
andTYPESENSE_PROTOCOL
, plus optionallyTYPESENSE_PATH
. This is inconvenient and in some cases problematic, because URLs are usually handled as strings. To pass a URL intotypesense-scraper
one needs to parse it and break up into components only forNode
to assemble them back. IfNode
constructor accepted plain URLs,typesense-scraper
could require just a single argument,TYPESENSE_URL
.At least in
typsesense-python
, the only usage forNode
's URL components is for building the whole URL and for building a shortened URL consisting only of the host and the port. This shortened representation is only used for logging, it could easily switch to printing full URLs, it would even be clearer.