Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API-endpoint not using POST-data #23

Open
DURK opened this issue Aug 1, 2013 · 0 comments
Open

API-endpoint not using POST-data #23

DURK opened this issue Aug 1, 2013 · 0 comments

Comments

@DURK
Copy link

DURK commented Aug 1, 2013

Hi,

I'm working on a Node API-server to create (what I'd like to call a) "Utils as a Service', as the main application is in C# and some features are easily achieved in Node. Currently, I'm working on a utility that gets html+js as import and DOM-rendered html (or image/pdf) as output.

The thing is, I'm having trouble finding out how to let my API-endpoint use POST-data, instead of GET-data or url-parsed data. In my case, input parameters as GET-variables aren't such a good idea.

I have the following setup:

Router
["/DOMrenderHtml/:html/:outputType", "v1/renderer#render"]

API module

/**
 * Renderer api-module
 */
var Renderer = module.exports = function (options) {
    var self = this
    options = (options !== null && options !== undefined && options.constructor === Object) ? options : {}
    Object.keys(options).forEach(function (key) {
        if (!self.__proto__.hasOwnProperty(key)) {
            self[key] = options[key]
        }
    })
};

/**
 * function: render
 */
Renderer.prototype.render = function (request, response) {
    //get parameters
    var html = request.querystring.html;
    var outputType = request.querystring.outputType;

What works:
curl http://localhost:3000/DOMrenderHtml/some-data/pdf/
Result::
request.querystring: { html: 'some-data', outputType: 'pdf' }

What I'm trying to do:
curl -X POST http://localhost:3000/DOMrenderHtml/ -d "{"html": "some-data", "outputType:"pdf"}" -H "Content-type: application/json"
Result::
request.querystring: { }
Nor is their any trace of my POST-data in the request-variable.

Conclusion:
What am I missing here? Couldn't find any example on how the actual API-call is expected to be made, except:

Server will respond to

GET, POST http://localhost:8080/foo
GET, POST http://localhost:8080/foo/5/true
GET, POST http://localhost:8080/foo_verbose/5
*         http://localhost:8080/bar
*         http://localhost:8080/1/foo_module/bar

Does this mean POST-data is not supported at all?

I would be very grateful for any help you are able to provide:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant