Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

REST API URL resource with parameter inside parentheses

In a project I am currently working on I was given the following HTTP POST command definition below (client requirement written in stone) which I have to implement into a webserver which is currently based on a MEAN STACK.

{{Host}}/Products('{{ProductId}}')/Data.Order

How can I implement this? I am not used to parameters inside parentheses for a specific resource.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Express should be able to resolve the path-placeHolder (through :<placeHolder>), even if it’s within this rather unusual parentheses. So try defining your endpoint as follows:

app.post('/Products(:productId)/Data.Order',(req, res, next) => {
    console.log("productId is", req.params.productId);

    res.status(201).end();
})

Calling this endpoint with POST http://<host>:<port>/Products(12345)/Data.Order should log 12345 to the console.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading