Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pathing #153

Merged
merged 12 commits into from
Jan 9, 2024
Merged

Support pathing #153

merged 12 commits into from
Jan 9, 2024

Conversation

jackkav
Copy link
Contributor

@jackkav jackkav commented Jan 6, 2024

motivation: as a user i might like to mock an api surface with multiple endpoints and responses a varying paths.

problem: mockbin generates an id on bin creation that is used for the path so paths that follow the id are ignored or unmatched by express.

aim: the following could all return different responses
bin/123-123-123-123/route-a
bin/123-123-123-123/route-b
bin/123-123-123-123/route-b/route-1

approach

  • include the path in the redis key
  • avoids making redis values into arrays of responses per path
  • use the url and a put method to indicate path to match

NOTE: you must first initialise a a mock response with a PUT request to a url you would like to mock with a HAR body of the response

to do

  • rotate log, view, sample endpoint paths to avoid conflict
    • alternatively since we only use log run and update, we could create a new route

Questions:

  • what should happen when and endpoint hasn't been initialised?

future work

  • validation, bad input errors,
    • do this later when we understand usage better
  • sanitization: trailing slashes, query params, max key size, perf implications,
    • do this later when we understand usage better
  • support mocked methods besides GET, eg POST, PUT, DELETE
    • will mean using the request body to configure the path rather than the url

@jackkav jackkav requested review from filfreire and gatzjames January 9, 2024 13:41
Copy link
Member

@filfreire filfreire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested locally. We found edge-case with trying to use bins directly on the mockbin ui when someone hits an endpoint that has not been initialised. Up for questions, but I think we can merge.

@jackkav jackkav merged commit 14b87d2 into master Jan 9, 2024
2 checks passed
@jackkav jackkav deleted the compound-id branch January 9, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants