smocker-dev / smocker Goto Github PK
View Code? Open in Web Editor NEWSmocker is a simple and efficient HTTP mock server and proxy
Home Page: https://smocker.dev
License: MIT License
Smocker is a simple and efficient HTTP mock server and proxy
Home Page: https://smocker.dev
License: MIT License
Could be great to try https://github.com/pzavolinsky/elmx
Maybe the Yarn cache and/or the Go modules folder should be cached in CI to speed up builds
This one is cool, and under CC BY License Smocker
I propose to add a 'headers' property on proxy section to define headers to be injected in the request before sending to proxy destination.
For example:
proxy:
host: https://example.com
headers:
X-Forwared-Proto: http
If ok, I can work on a pull request.
It would be great if we can place some (YAML) mock definitions in a specific path and Smocker
will pick up those and register them.
It could be great to add hcl format support for mock definition.
https://github.com/hashicorp/hcl
It could be great in the history page to be able to copy request as curl command to easily reproduce calls
UUIDs are too long and not really readable. Some alternatives would be more readable:
_
and -
, just [a-z0-9]
or even just [a-z]
smock is already taken
Currently, the bundled js file is too big (1.24 MB)
It would be great to try to reduce it (maybe by using tree shaking or parcel plugins)
With this mock for example:
request:
method: GET
path: /foo
context:
times: 3
response:
status: 200
If a client runs 10 calls in parallel to /foo, there's a risk that the mock server replies more than 3 times
I pasted a mock with a large payload in the mock editor and it collapsed in the "payload too large" button :D
It should not happen
A nice to have workflow would be the following:
- request:
method: # The request method
path: # The request path
query_params: # The request query params
headers: # The request headers (the user can remove the unnecessary ones as needed, but maybe we can filter some of them)
# no body
- response:
status: 200
headers:
Content-Type: application/json
body: >
It's very common for services to callback some URI after some was processed — read: webhook call. This may happens after a certain period of time.
It would be nice if Smocker will be able to make those webhook calls after a given mock definition is executed. For instance, to simulate that a service received the HTTP call and based on the input it will respond back to /path/to/webhook
with response
within x
seconds.
Not sure if this is doable with proxies.
The most useful filter would be "Show Smocker errors", that would filter on response codes >= 600
Right now, the request body is a basic StringMatcher
. This limits a lot how we can manipulate it.
At the minimum, it would be nice to be able to perform rich matching on a JSON body field.
For example, if we want to match a body containing a foobar
key with the value "Hello, World", for instance:
{
"foobar": "Hello, World"
}
the best we can do right now is something like:
request:
body:
matcher: ShouldMatch
value: '"foobar":\s*"Hello, World!"'
A better way to do it would be to apply matchers on the individual body field, by parsing it as JSON, for example:
request:
body:
foobar: Hello, World
This allows us to apply powerful matching strategies, such as:
request:
body:
foobar:
matcher: ShouldMatch
value: Hello, (.+)
For nested fields, the syntax could use stretch/objx (.
for nested keys, [n]
for arrays). Examples:
request:
body:
my_array[2]: foo
parent_key.child_key: bar
Session names should be unique, and sessions created with POST /sessions?name=xxx
should overwrite the previous session with the same name.
Maybe the POST /sessions?name=xxx
should be replaced with a PUT /sessions?name=xxx
On request
Could be linked to ant-design/parcel-antd#12 (which should also reduce bundle size)
Currently Smocker can work as a http proxy if you try to call an API using http_proxy variable. The call will be redirected to Smocker.
You can test this by:
make start
export http_proxy=http://localhost:8080/
curl -v http://jsonplaceholder.typicode.com/todos/1
Then you should see the call on Smocker.
But when we try to make a call using HTTPS and HTTPS_PROXY, the http client send a CONNECT request on the proxy server which is not handled correctly by Smocker.
It will respond to the call with a "No mock found matching the request" which will cancel the https request on client side.
TSLint has been deprecated in favor of ESLint.
Maybe don't load huge payloads on the DOM directly but ask confirmation to the user.
Example: button "This payload is huge. Click to display it"
With the following workflow:
If the response is not what I want for my test, I would like to be able to easily create a mock from the UI even if the call was successful to override a specific proxy response
I'm working with ancient APIs these days. The responses are JSON or XML files around 3,000 (even more) lines length.
I would like to use Smocker at the new work place, but so far I haven't found a way to do something like this with Smocker:
- request:
method: GET
path: /hello/world
response:
headers:
Content-Type: application/json
body: file:/path/to/hello_world_response.json
I'm aware this not even valid YAML, but the file:/path/to/hello_world_response.json
is just an example of what I'm trying to do, which is only to refer to a file with the content of the body, instead of putting the gigantic response there. If that's impossible to do these days, it would be nice to have a declarative way to implement such things in the YAML configuration file — probably with a fixed location for these kind of files.
Moreover, those are usually templates, because there is always something that needs to be changed before sending them back to the user-agents.
like soapUI does and use them in response templates by injecting them in the lua state
Only the errors 500 generated by a proxied request, not mocks that explicitly return a 5xx error
/Users/thiht/workspace/go/bin/reflex --start-service \
--decoration='none' \
--regex='\.go$' \
--inverse-regex='^vendor|node_modules|.cache/' \
-- go run -ldflags="-X main.appName=smocker -X main.buildVersion=snapshot -X main.buildCommit=1fdcb52b32d9c00763fe2b106e924527e1e97c3d -X main.buildDate=2020-07-18T17:21:43+0200" main.go --log-level=debug --static-files ./build --persistence-directory ./sessions
Starting service
INFO[2020-07-18T17:21:49+02:00] Setting log level log-level=debug
ERRO[2020-07-18T17:21:49+02:00] Unable to load sessions: stat ./sessions: no such file or directory
the folder and the files should be created automatically if they don't exist
The loader should replace the "load session" button (spinner)
It could be great to have a full working real world example:
Introduce:
Add a new option to keep Host
HTTP header in requests to the proxy destination.
Hi,
I'm currently trying to use smocker with a proxy mock which access https. The problem is now, that I get
Error during request redirection: Get "https://....": x509: certificate is valid for ... not ...."
or if using the IP:
Error during request redirection: Get "https://....": x509: certificate signed by unknown authority
back.
Is it possible to tell smocker to ignore certificate errors?
When the response of a 'proxy' mock is a redirection, for example an HTTP 302, smocker follow the redirection instead of forwarding the response back. This is not expected for a reverse proxy.
When creating a new mock from entry an entry with a JSON body on the UI, something like this is generated:
- request:
path: ...
method: ...
body:
a:
b: 3
instead of:
- request:
path: ...
method: ...
body:
a.b: 3
We should generate something following objx format, or not generate anything at all for the body
The following syntaxes are supported:
headers:
X-Example-Header: test
headers:
# multiple occurrences
X-Example-Header: [test, test2, test3]
headers:
X-Example-Header:
# array is required even for a single matcher
- matcher: ShouldMatch
value: test.*
The following should be allowed as well:
headers:
X-Example-Header:
# no array
matcher: ShouldMatch
value: test.*
For example the POST /mocks?newSession=<name>
is not documented, maybe there are some other things too
Hi folks, I would like to know how to define a random delay when defining a mock using go templates
It could be great to be able to set the maximum number of messages we want to store by session
Why:
Using that we could be able to use smocker as à dev gateway without worrying that memory increases as calls are made.
How:
On each call we can compare the history size to the retention and remove the oldest one when len(history) > retention
Maybe instead of "Matched mock", show "Redirected" or something like that
When we have a 666 error code, we know the body contains a Smocker error.
We could display a more beautiful error message on the UI in this case
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.