peterknezek / har-to-mocks

Extract response from .har file and create JSON mocks for mock server.
MIT License
23 stars 12 forks source link

How to make `HAR to Mock` for non `api` directive request?` #10

Closed aaggarwal10 closed 1 year ago

aaggarwal10 commented 1 year ago

Hi, I am currently really liking how easy it is to get json responses from the HAR network traffic file. However, I am currently struggling on trying to get these responses for a non api directive. For example, I can easily get these requests for localhost:3000/api/session/user but I can not get the responses for localhost:3000/lumina-api/auth/log-in even when changing the --url=lumina-api flag. I would really appreciate the help and support.

Sincerely, Anish

peterknezek commented 1 year ago

Hi, thank you that's really nice.

The filtering by url is checking if the matches are existed in the whole URL.

$ har-to-mocks ./tests/mocks/sample.har --url=lumina-api
Filtered requests:

 Name                    Method Path                        
 ─────────────────────── ────── ─────────────────────────── 
 log-in                  GET    3000/lumina-api/auth/log-in 

So, if the URL is not included in the results maybe it's filtered out by other parameters. By default they're applied --method=GET and --type=xhr.

Try to check in Chrome > DevTools > Network if the request is: Request Method: GET or type: xhr.

aaggarwal10 commented 1 year ago

Hi so I checked the request method and type, and it turns out that it uses a POST method with the type fetch. I know I can change the method properly to Post, but I was wondering if you knew how to also query for the fetch type.

peterknezek commented 1 year ago

Hi, request type fetch wasn't supported, so I added it to the list and in the v1.1.6 it should work

$ har-to-mocks ./tests/mocks/sample.har --url=lumina-api --method=POST --type=fetch