BackendStack21 / restana

Restana is a lightweight and fast Node.js framework for building RESTful APIs.
MIT License
467 stars 27 forks source link

Cannot add query string on POST request ? #91

Closed rgrenonlkr closed 4 years ago

rgrenonlkr commented 4 years ago

Hello,

When adding a query string to a POST request it returns 404

code style : service.use("/path/to/entity", router_entity);

router_entity defines : router.post("/", async (req, res, next) => {

I tried with and without swagger middleware but got same result.

Any advise ?

Regards,

jkyberneees commented 4 years ago

Hi @rgrenonlkr, can you bring more context of your source code? I can't repro this issue on my side.

Please see an example here you can use:

'use strict'

const service = require('restana')({})
const router = service.newRouter()
router.post('/params', (req, res) => {
  res.send({ query: req.query })
})
service.use('/router', router)

service.start()

curl --location --request POST 'http://localhost:3000/router/params?age=30'
rgrenonlkr commented 4 years ago

Hi,

I changed the paths/pattern of your example to match those used in my initial post. Then I get the 404

'use strict'

const service = require('restana')({})
const router = service.newRouter()
router.post('/', (req, res) => {
  res.send({ query: req.query })
})
service.use('/router/params', router)

service.start()

EDIT : wording

jkyberneees commented 4 years ago

Hi, now I get your problem.

Unfortunately, this is a limitation from how the router works in the low level, in this case with middlewares and routers. You can see more details at: https://github.com/lukeed/regexparam/blob/master/src/index.js, loose parameter.

A workaround is to use: POST http://localhost:3000/router/params/ as endpoint, see ending /

Regards

rgrenonlkr commented 4 years ago

Hi,

You're totally right ! My code defines this pattern ...endpoint/?params or ...endpoint But I expect it to match ...endpoint?params

Since this is a computer-to-computer API it will be easier for me specify the mandatory / when using params.

Thanks a lot for your help