kilianc / kilianc/node-apiserver
API-endpoint not using POST-data
- Dominant language
- JavaScript
- Stars
- 224
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Description
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:)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the router declaration and Renderer.prototype.render in the issue, then trace how the server builds the request object for POST requests. Reproduce the supplied curl request and compare it with the working URL-parameter request. Done means the documented POST JSON payload is available to the renderer and is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100