node-apiserver icon indicating copy to clipboard operation
node-apiserver copied to clipboard

API-endpoint not using POST-data

Open DURK opened this issue 11 years ago • 0 comments

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:)

DURK avatar Aug 01 '13 09:08 DURK