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

[Feature] Customizable Fake HTTP Responses #47

Open
butschster opened this issue May 14, 2023 · 2 comments
Open

[Feature] Customizable Fake HTTP Responses #47

butschster opened this issue May 14, 2023 · 2 comments

Comments

@butschster
Copy link
Member

butschster commented May 14, 2023

This feature request proposes the introduction of a functionality in Buggregator that allows users to respond to HTTP requests with customizable fake responses, based on schemas provided by the user. This would greatly enhance the testing and debugging capabilities of Buggregator.

Current Limitations

While Buggregator currently has the ability to catch HTTP requests and display comprehensive information (method, URI, payload, etc.), it lacks the feature to actively respond to these requests with predefined, user-customized fake responses.

Proposed Feature

  1. Custom Response Creation: Allow users to define custom responses for intercepted HTTP requests. This includes the ability to specify the status code, headers, body, and delay time for the response.

  2. Response Schema Definition: Enable users to create response schemas in json format.

  3. Conditional Response Logic: Implement logic to match requests with appropriate fake responses based on criteria such as request method, URI, payload content, or headers.

Benefits

  1. Enhanced Testing Capabilities: Developers can test client-side handling of various server responses without needing the backend to actually provide these responses.

  2. Improved Debugging: This feature would allow developers to simulate server-side errors or delays to test how the front-end handles these scenarios.

  3. Faster Development Cycle: By simulating backend responses, front-end development can proceed without waiting for backend implementation, leading to a more efficient development cycle.

  4. User Experience Testing: It enables testing of different user experience flows based on various server responses, improving the robustness of the application.

Use cases

  1. Front-end Development: Front-end developers can simulate backend responses to test UI components and error handling mechanisms.

  2. API Testing: Test how your application responds to unexpected or error responses from a server.

Draft JSON schema for response definition

{
   "title":"User Creation Schema",
   "match":{
	   "url": "user/store",
	   "method": "POST",
	   "headers": [
	          {"X-Response-Type": "success"}
	   ],
   },
   "response": {
	   "statusCode": 200,
	   "headers": [
	          {"Foo": "Bar"}
	   ],
	   "cookies": [
	          {"Foo": "Bar"}
	   ],
	   "serverAttributes": [
	          {"Foo": "Bar"}
	   ],
	   "properties":{
	      "username":{
	         "type":"string",
	         "provider":"userName",
	         "description":"User's chosen username."
	      },
	      "email":{
	         "type":"string",
	         "format":"email",
	         "provider":"email",
	         "description":"User's email address."
	      },
	      "password":{
	         "type":"string",
	         "provider":"password",
	         "description":"User's chosen password."
	      },
	      "fullName":{
	         "type":"string",
	         "provider":"name",
	         "description":"User's full name."
	      },
	      "userId":{
	         "type":"integer",
	         "provider":"randomNumber(1, 100)",
	         "description":"User's ID."
	      },
	      "status":{
	         "type":"string",
	         "provider":"randomElement(['new', 'success', 'failed'])",
	         "description":"User's status."
	      },
	      "address":{
	         "type":"object",
	         "properties":{
	            "street":{
	               "type":"string",
	               "provider":"streetAddress"
	            },
	            "city":{
	               "type":"string",
	               "provider":"city"
	            },
	            "state":{
	               "type":"string",
	               "provider":"state"
	            },
	            "zipCode":{
	               "type":"string",
	               "provider":"postcode"
	            }
	         }
	      },
	      "phoneNumber":{
	         "type":"string",
	         "provider":"phoneNumber",
	         "description":"User's phone number"
	      }
	   },
   }
}

In this schema, each property includes a provider field that specifies the FakerPHP method used to generate the mock data for that field. This setup is particularly helpful for automated testing or when populating a database with mock data for development purposes.

The match object indicates that both url and method are mandatory for the matching process, ensuring that the response is linked to a specific type of request. This setup is useful for mock servers or testing environments where you need to simulate responses based on different request scenarios.

@butschster butschster changed the title [Feature] Swagger faker [Feature] Swagger faker for http dump May 14, 2023
@butschster butschster self-assigned this May 21, 2023
@butschster butschster added the help wanted Extra attention is needed label May 21, 2023
@butschster butschster removed their assignment May 21, 2023
@butschster butschster added enhancement New feature or request for contributors c: difficult module [Http-dump] and removed help wanted Extra attention is needed labels Aug 7, 2023
@butschster butschster changed the title [Feature] Swagger faker for http dump [Feature] Customizable Fake HTTP Responses Dec 5, 2023
@butschster butschster added this to the 2.0 milestone Dec 5, 2023
@butschster butschster self-assigned this Dec 5, 2023
@butschster butschster pinned this issue Dec 5, 2023
@butschster
Copy link
Member Author

@butschster
Copy link
Member Author

Possible implementation here https://github.com/mcustiel/phiremock-server

@butschster butschster unpinned this issue Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant