tomas / tomas/needle

Relative url (not port 80)

Open
#249 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.6k
Forks
237
PR merge metrics
No merged PRs in 30d

Description

Great lightweight implementation! I'm quite the node noob, and not a developer by trade, just a hobbyist...

One issue I had was being required to use an absolute url to make my post requests on the node server, because I'm not listening on port 80. In my case, port 3001 for a test server. Using:

var url = '/gpio/'; 
needle.post(url, {}, function (err, resp){
if (err){console.log(err)};
})

Note: In my implementation, I'm just hitting a raspberry pi's GPIO with an API using a post request to trigger some relays, hence an empty data block.

My solution was to grab the hostname first from the request object, which is easy enough, so in my express route, I just added....

var host = 'http://' + req.headers.host;
var api = '/gpio/';
var url = host + api;
needle.post(url, {}, function (err, resp){
if (err){console.log(err)};

I'm not sure if it's worth adding into the code to do this automatically to allow for implementations outside of port 80 or at least just to document that an absolute url is required.

Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing needle.post with the relative URL example and reviewing how request URLs are handled and documented. Compare the absolute URL on port 3001 with the relative /gpio/ form; done means the project either supports the relative form or clearly documents that absolute URLs are required.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.