smollweide / node-mock-server

File based Node REST API mock server
MIT License
255 stars 65 forks source link

Access to request object from json response #132

Closed sebastienfouache closed 5 years ago

sebastienfouache commented 5 years ago

Hello, i mocked a response on /save and i want to record in a file all calls done to this endpoint. In the /save json response file i have to get the request path and body.

Alternative solution : do you have any recording feature ? I have to make e2e tests and record all calls and query calls from a diagnostic endpoint. Exemple : Get last post call on /save : return the last request and response on this endpoint. /metrics/save/post/last

smollweide commented 5 years ago

Hi, I‘m not 100% sure what you mean but there are two feature which could possibly help you:

Tunnel allow you to record real request by tunneling the request to the real api and storing the response:

https://github.com/smollweide/node-mock-server/blob/master/doc/readme-tunnel.md

Collections allow you to restore a specific response configuration. Which is very useful for automatic testing.

https://github.com/smollweide/node-mock-server/blob/master/doc/readme-collections.md

Hope that is what you looking for.

Happy coding :)

sebastienfouache commented 5 years ago

I will use middleware feature to record specific endpoints in a file and expose the record results with expressMiddleware to get the file.

sebastienfouache commented 5 years ago

Thank you for your quick answer.