0

I'm working on a simple mock server, and am using nothing but JavaScript and Yarn to build it.

In a simplistic manner, I have this that's working as intended:

function server() {
(...)

return {
    users: generate(userGenerator, 150)
}

This is generating 150 random users, when the /users endpoint is reached, and it's working as intended. The issue I'm having is with catching id's passed on the query string. ie:

/users/{id}/attribute

How can I get this to work?

Many thanks in advance

1

1 Answer 1

1

try req.params.id

app.get('/users/:id/attribute', function(req, res) {
    console.log('id : ' + req.params.id);
    ...
});
Sign up to request clarification or add additional context in comments.

6 Comments

You didn't show how to catch them though. Only how to get them. The OP wants to catch them
can you explain what do you mean by 'catch them'? i will try my best to answer it.
dont you have to write an express app?
The mock I'm creating is for testing purposes. The id is irrelevant, but it has to be there, so the people using this mock can retain the structure they have on their API calls. I simply want to be able to return values and declare something along the lines of /user/:id/attribute as a usable endpoint, that returns random attributes. I cannot use special characters on the return statement that I have defining the endpoints, thus I assume I must parse the query string after reaching /users/, and then evaluate what's on the query string, and return accordingly. I just don't know how to do so
is it a node.js + express app?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.