<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pete Cornish on Medium]]></title>
        <description><![CDATA[Stories by Pete Cornish on Medium]]></description>
        <link>https://medium.com/@outofcoffee?source=rss-5b8a71ae725------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2ERyd90ffS_dv0tr.png</url>
            <title>Stories by Pete Cornish on Medium</title>
            <link>https://medium.com/@outofcoffee?source=rss-5b8a71ae725------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 20:44:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@outofcoffee/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[WSDL Web: like SwaggerUI but for WSDL/SOAP web services]]></title>
            <link>https://medium.com/@outofcoffee/wsdl-web-like-swaggerui-but-for-wsdl-soap-web-services-28511011c7e8?source=rss-5b8a71ae725------2</link>
            <guid isPermaLink="false">https://medium.com/p/28511011c7e8</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[web-services]]></category>
            <category><![CDATA[soap]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[wsdl]]></category>
            <dc:creator><![CDATA[Pete Cornish]]></dc:creator>
            <pubDate>Mon, 27 Jul 2026 22:23:28 GMT</pubDate>
            <atom:updated>2026-07-27T22:23:28.337Z</atom:updated>
            <content:encoded><![CDATA[<p>Someone hands you a WSDL URL and says “integrate with this.” It’s a SOAP service. Before you can write a line of client code you need to know what operations it exposes, what a request looks like, and whether the thing even responds. The options have been the same for years: install SoapUI and wait for it to load, or hand-build envelopes in Postman or curl, getting the namespaces, the SOAPAction header and the envelope structure exactly right before you get a single response back. All of that just to poke at an endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v9lRnRPLfBNT9tRTYmbNKg.png" /></figure><p>Then OpenAPI came along and Swagger UI. Great for REST-like APIs, but what about all those existing WSDL documents still in existence?</p><p><a href="https://wsdl-web.github.io/">WSDL Web</a> is like Swagger UI, but for SOAP. Paste a WSDL URL and it shows you every service, endpoint and operation, generates a ready-to-send SOAP request for each one, and lets you fire it off and read the response, all in the browser. Open source (Apache 2.0).</p><p>This post walks through using it, from the zero-install hosted page to running your own copy and building it into your own tools.</p><h3>The zero-install way: just open the page</h3><p>The quickest way to try it is the hosted version at <a href="https://wsdl-web.github.io/">wsdl-web.github.io</a>. Nothing to install, no backend, no account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g7jfnAC0ahn_x9UYBU5x-w.png" /></figure><p>Paste a WSDL URL into the top bar and click Explore. WSDL Web fetches and parses it, then shows the service name, target namespace, and the endpoints and operations grouped underneath. Open an operation and you get its endpoint address, SOAPAction, binding style, and a SOAP request envelope generated from the XSD types, with sample values already filled in. Any &lt;wsdl:documentation&gt; in the WSDL is shown inline as well.</p><p>If you want to see it working without hunting down a WSDL first, there’s a sample you can load in one click:</p><p><a href="https://wsdl-web.github.io/?url=sample.wsdl">https://wsdl-web.github.io/?url=sample.wsdl</a></p><p>The ?url= parameter is a link-friendly way to preload any WSDL from a URL. You can also add a fragment like #Service/Endpoint/Operation to jump straight to a particular operation:</p><p><a href="https://wsdl-web.github.io/?url=https://example.com/service?wsdl#StockQuote/StockQuoteSoap/GetQuote">https://wsdl-web.github.io/?url=https://example.com/service?wsdl#StockQuote/StockQuoteSoap/GetQuote</a></p><p>The URL updates as you navigate, so you can copy it out of the address bar and send someone a link that opens on the exact operation you’re looking at. Handy for directing someone to a particular part of an API: here’s the operation, go.</p><p>It copes with the awkward corners of real WSDLs, too. WSDL 1.1 and 2.0 are detected automatically, SOAP 1.1 and 1.2 are both supported, document and RPC bindings both work, and &lt;wsdl:import&gt;, &lt;xsd:import&gt; and &lt;xsd:include&gt; are followed recursively across files and merged back together. You can also load several WSDLs at once and switch between them from a dropdown.</p><h3>Actually calling the service: Try it out</h3><p>One of the great things about Swagger UI was that reading an API is <em>useful</em>, but what’s really helpful is sending a request right from the spec and seeing what comes back.</p><p>Click Try it out on any operation and the generated envelope becomes editable. Change the values, add whatever the request needs, then click Execute. WSDL Web sends the SOAP request and shows you the HTTP status, the response time, and the full response body with XML syntax highlighting. If the service returns a &lt;soap:Fault&gt;, it&#39;s picked out and rendered as faultcode, faultstring and detail, rather than leaving you with a wall of XML to squint at.</p><p>A few other things make this less painful than hand-rolling requests:</p><ul><li>Pop an Authorization header, an API key or a WS-Security token in the request.</li><li>Override the base URL to send the request somewhere other than the address baked into the WSDL: http://localhost:8080 while you test against a local instance, say.</li><li>Copy the request you’ve just built as a ready-to-run cURL command, to drop into a script or a ticket.</li></ul><p>There’s no fighting with envelope structure or namespaces to get a first response. The generator handles this for you, leaving you to edit the values sent in the request.</p><h3>Everything stays in your browser</h3><p>WSDL Web is handy if you work with internal or sensitive services: it has no backend. There’s nothing to upload anything to, because there’s no server at all. The hosted version is just static files on a web server.</p><p>Concretely:</p><ul><li>The WSDL is fetched and parsed in your browser. The request envelopes are generated in your browser.</li><li>When you click Execute, the request goes straight from your browser to the service. It doesn’t pass through wsdl-web.github.io, or anywhere else.</li><li>Nothing is stored. No accounts, no cookies, no localStorage, no analytics or telemetry. Close the tab and there’s nothing left behind.</li><li>You can load a WSDL straight from your own disk with the Browse button, and that file never leaves your machine.</li></ul><p>That last point is the common case for enterprise SOAP: the WSDL lives on an internal network or as a file on your laptop, and it should stay there.</p><p>This highlights one trade-off of this design: because requests go directly from your browser to the service, they’re subject to the browser’s same-origin policy, and SOAP services rarely send CORS headers, so a cross-origin request may be blocked. When that happens you have a few options: run WSDL Web from the same origin as the service (more on that next), put a CORS proxy in front of it, or use the base URL override to point at one.</p><h3>Run your own copy</h3><p>Sometimes you don’t want to depend on a public page at all. Maybe you’re on a locked-down network, or you’d rather serve the app from the same origin as your services and sidestep CORS entirely. WSDL Web also ships as a Docker image:</p><pre>docker run -p 8080:80 outofcoffee/wsdl-web</pre><p>Open http://localhost:8080 and you have the same explorer, running inside your own perimeter. It&#39;s a static site, so you can equally drop the built files onto S3, an nginx server etc. - basically anywhere that serves HTML.</p><h3>Build it into your own tools</h3><p>If you maintain a developer portal, an internal wiki or a set of API docs, you can embed the explorer directly instead of sending people to a separate app. You can do this in a couple of ways:</p><p>The standalone bundle needs no build step. It’s a stylesheet, a script tag and one function call:</p><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;wsdl-web.css&quot; /&gt;<br>&lt;div id=&quot;wsdl-web&quot;&gt;&lt;/div&gt;<br>&lt;script src=&quot;wsdl-web.js&quot;&gt;&lt;/script&gt;<br>&lt;script&gt;<br>  WsdlWeb.init(document.getElementById(&#39;wsdl-web&#39;), {<br>    url: &#39;https://example.com/service?wsdl&#39;,<br>  })<br>&lt;/script&gt;</pre><p>If you already have a React app, install the npm package and use the component:</p><pre>import { WsdlWeb } from &#39;wsdl-web&#39;<br>import &#39;wsdl-web/style.css&#39;<br><br>function ServiceExplorer() {<br>  return &lt;WsdlWeb url=&quot;https://example.com/service?wsdl&quot; /&gt;<br>}</pre><p>Both take the same options. A common one is to lock the explorer to a single service and hide the input controls, so the page reads as purpose-built rather than a general tool:</p><pre>&lt;WsdlWeb<br>  url=&quot;https://example.com/service?wsdl&quot;<br>  showUrlInput={false}<br>  showExploreButton={false}<br>  showBrowseButton={false}<br>/&gt;</pre><p>Or list several services and let people switch between them from a dropdown. This gives you a live, explorable catalogue of your SOAP APIs sitting inside your own docs:</p><pre>&lt;WsdlWeb<br>  urls={[<br>    { label: &#39;Users API&#39;, url: &#39;https://example.com/users?wsdl&#39; },<br>    { label: &#39;Orders API&#39;, url: &#39;https://example.com/orders?wsdl&#39; },<br>    { label: &#39;Inventory&#39;, url: &#39;https://example.com/inventory?wsdl&#39; },<br>  ]}<br>/&gt;</pre><p>There’s a baseUrlOverride option too, for routing embedded requests through a proxy. The full set of options is in the <a href="https://github.com/wsdl-web/wsdl-web/blob/main/docs/embedding-standalone-web-bundle.md">standalone bundle</a> and <a href="https://github.com/wsdl-web/wsdl-web/blob/main/docs/embedding-npm-package.md">npm package</a> guides.</p><h3>Summary</h3><p>WSDL Web turns a WSDL URL into something you can explore and call, without installing a desktop client or hand-writing envelopes. Start on the hosted page at <a href="https://wsdl-web.github.io/">wsdl-web.github.io</a>, run your own copy with a one-line Docker command, or embed it in your own portal. In every case the parsing and the requests happen in your browser, with nothing stored and nothing routed through a server in the middle.</p><p>It’s open source, under Apache 2.0. The code, docs and embedding guides are on <a href="https://github.com/wsdl-web/wsdl-web">GitHub</a>, and the documentation site is at <a href="https://wsdl-web.github.io/wsdl-web">wsdl-web.github.io/wsdl-web</a>.</p><p>Once you’ve explored a SOAP service, the next step is often to mock it, so you can build against it without the real thing having to be up. That’s what <a href="https://www.imposter.sh/">Imposter</a> and the hosted <a href="https://www.mocks.cloud/">Mocks Cloud</a> are for: point them at the same WSDL and get a live mock endpoint back. But that’s a <a href="https://medium.com/@outofcoffee/mocking-soap-web-services-with-imposter-da8e9666b5b4">different</a> post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O7UO_NZtS59NRvkOM7jXLw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28511011c7e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mocking the OpenClaw Gateway with Imposter]]></title>
            <link>https://medium.com/@outofcoffee/mocking-the-openclaw-gateway-with-imposter-3bfd9abfbdbe?source=rss-5b8a71ae725------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bfd9abfbdbe</guid>
            <dc:creator><![CDATA[Pete Cornish]]></dc:creator>
            <pubDate>Tue, 14 Jul 2026 19:16:30 GMT</pubDate>
            <atom:updated>2026-07-14T20:56:11.806Z</atom:updated>
            <content:encoded><![CDATA[<p>A lot of the interesting work around AI agents right now is in the tooling: the operator consoles, CLIs, dashboards and background workers that drive agents, manage their sessions and stream results back to a human. <a href="https://docs.openclaw.ai/">OpenClaw</a> sits at the centre of a lot of this. Its gateway is the control plane between operator clients and the nodes that run the work, and it all happens over a single WebSocket connection.</p><p>Building a client for that gateway is where it gets awkward. A live gateway means a live agent behind it: responses aren’t deterministic, you need real nodes paired to get anywhere, runs are slow, and each one costs tokens. Pinning down a specific sequence (a tool call, then a streamed reply, then a reconnect) so you can build against it or assert on it in CI is most of the battle.</p><p>That’s the same reason you’d mock a REST or SOAP API, and Imposter now handles it. This post shows how to mock the OpenClaw gateway’s WebSocket API using <a href="https://www.imposter.sh/">Imposter</a>.</p><h3>The gateway protocol, briefly</h3><p>The gateway speaks JSON frames over one WebSocket. Three kinds:</p><ul><li>requests: {&quot;type&quot;:&quot;req&quot;,&quot;id&quot;:&quot;…&quot;,&quot;method&quot;:&quot;…&quot;,&quot;params&quot;:{…}}</li><li>responses: {&quot;type&quot;:&quot;res&quot;,&quot;id&quot;:&quot;…&quot;,&quot;ok&quot;:true,&quot;payload&quot;:{…}}</li><li>events: {&quot;type&quot;:&quot;event&quot;,&quot;event&quot;:&quot;…&quot;,&quot;payload&quot;:{…}}, pushed by the server</li></ul><p>A client connects and gets a connect.challenge event, sends a connectrequest, and receives hello-ok. After that it lists agents and sessions, then sends a chat.send. Instead of one reply it gets an acknowledgement, followed by a stream of agent and chat events as the run plays out. A tick event fires periodically to keep the connection alive.</p><p>Request/response is easy enough to fake. The streams and the periodic pushes are the parts that trip up a traditional mock, and they’re the parts an agent client leans on most.</p><h3>A WebSocket mock</h3><p>Imposter 5.x has a built-in websocket plugin. A resource says when to act (on open, on a matching message, or on close) and what to send back. The matching, capture and <a href="https://docs.imposter.sh/templates/">templating</a> are the same ones you&#39;d use in a REST mock.</p><p>Start with the connection itself. On open, send the challenge and kick off the keepalive:</p><pre># imposter-config.yaml<br>plugin: websocket<br><br>resources:<br>  - path: /*<br>    on: open<br>    response:<br>      content: &#39;{&quot;type&quot;:&quot;event&quot;,&quot;event&quot;:&quot;connect.challenge&quot;,&quot;payload&quot;:{&quot;nonce&quot;:&quot;${random.uuid()}&quot;,&quot;ts&quot;:${datetime.now.millis}}}&#39;<br>      template: true<br>    schedule:<br>      - every: 15s<br>        response:<br>          content: &#39;{&quot;type&quot;:&quot;event&quot;,&quot;event&quot;:&quot;tick&quot;,&quot;payload&quot;:{&quot;timestamp&quot;:${datetime.now.millis}}}&#39;<br>          template: true</pre><p>The path: /* accepts a connection on any path, which is how the real gateway behaves: it multiplexes on one port and upgrades on the Upgrade: websocketheader, not a fixed URL. ${random.uuid()} and ${datetime.now.millis} are filled in per connection, so the nonce and timestamps look live.</p><h3>Answering a request</h3><p>Match incoming messages on the JSON-RPC method, and capture the request idso you can echo it back:</p><pre>- path: /*<br>    requestBody:<br>      allOf:<br>        - jsonPath: $.type<br>          value: req<br>        - jsonPath: $.method<br>          value: connect<br>    capture:<br>      reqId:<br>        requestBody:<br>          jsonPath: $.id<br>    response:<br>      content: &#39;{&quot;type&quot;:&quot;res&quot;,&quot;id&quot;:&quot;${stores.request.reqId}&quot;,&quot;ok&quot;:true,&quot;payload&quot;:{&quot;type&quot;:&quot;hello-ok&quot;,&quot;protocol&quot;:4}}&#39;<br>      template: true</pre><p>One resource per method (agents.list, sessions.list, sessions.create, models.list) and the mock will carry a client through its whole startup handshake to a working chat screen.</p><h3>Streaming a reply</h3><p>A single chat.send kicks off a whole run&#39;s worth of events, spread out over time. Imposter models that with a responses list, each entry a full response with its own delay:</p><pre> - path: /*<br>    requestBody:<br>      allOf:<br>        - jsonPath: $.type<br>          value: req<br>        - jsonPath: $.method<br>          value: chat.send<br>    capture:<br>      reqId:<br>        requestBody: { jsonPath: $.id }<br>    responses:<br>      - content: &#39;{&quot;type&quot;:&quot;res&quot;,&quot;id&quot;:&quot;${stores.request.reqId}&quot;,&quot;ok&quot;:true,&quot;payload&quot;:{&quot;runId&quot;:&quot;${stores.request.reqId}&quot;,&quot;status&quot;:&quot;started&quot;}}&#39;<br>        template: true<br>      - file: agent-tool-start.json<br>        delay: { exact: 300 }<br>        template: true<br>      - file: agent-tool-result.json<br>        delay: { exact: 300 }<br>        template: true<br>      - file: chat-event-delta.json<br>        delay: { min: 100, max: 400 }<br>        template: true<br>      - file: chat-event-final.json<br>        delay: { exact: 400 }<br>        template: true</pre><p>The frames go out in order with real gaps between them: a tool call, its result, a couple of chat deltas, then the final message. Your streaming UI gets a proper workout, and it does the same thing every time. No model, no tokens.</p><p>The tick from the open resource, meanwhile, keeps firing on its 15-second <a href="https://docs.imposter.sh/scheduled_tasks/">schedule</a> for as long as the connection is open. Schedules aren&#39;t specific to WebSocket. The same feature drives cron- or interval-based HTTP calls, which is handy for webhook-style pushes, but a keepalive is a natural fit too.</p><h3>Starting the mock</h3><p>The plugin is built in, so there’s nothing to install. With the <a href="https://docs.imposter.sh/run_imposter_cli/">Imposter CLI</a>:</p><pre>imposter up</pre><p><strong><em>Tip: Imposter not installed? </em></strong><em>Install using Homebrew:<br></em>brew install imposter-project/imposter/imposter</p><p>Imposter listens on http://localhost:8080 and takes a WebSocket connection on any path.</p><h3>Trying it out</h3><p>Any client works. Here’s <a href="https://github.com/vi/websocat">websocat</a>:</p><pre>websocat ws://localhost:8080/ws</pre><p>The connect.challenge arrives straight away. Send a handshake:</p><pre>{&quot;type&quot;:&quot;req&quot;,&quot;id&quot;:&quot;req-1&quot;,&quot;method&quot;:&quot;connect&quot;,&quot;params&quot;:{}}</pre><p>and hello-ok comes back. Send a chat.send and watch the acknowledgement turn into a stream of tool and chat events, with a tick every 15 seconds.</p><h3>Building against it: Lucinate</h3><p><a href="https://lucinate.ai/">Lucinate</a> is an operator client for OpenClaw agents: it connects to a gateway, browses agents and sessions, and runs a live chat. A mock gateway covers exactly that flow. You can build the connect-list-open-chat path, drive the streaming UI frame by frame, and run it in CI, none of it needing a paired node or a single token. Point the finished client at a real gateway afterwards and nothing about the wire protocol changes.</p><p>We can test our mock interactively using Lucinate.</p><pre>brew install lucinate-ai/tap/lucinate</pre><p>Start Lucinate with lucinate then add a connection using the following settings:</p><ul><li>Type: OpenClaw</li><li>URL: <a href="http://localhost:8080/">http://localhost:8080</a></li></ul><p>Once you’re connected, choose an agent, and start chatting!</p><h3>Summary</h3><p>The websocket plugin brings Imposter&#39;s matching, capture and templating to a bidirectional, streaming protocol. The responses list handles the streamed events, and connection-scoped schedules handle the periodic pushes. Between them they cover the request/response-and-events shape that agent gateways like OpenClaw use. Config changes need a restart (CTRL+C to stop).</p><p>For the full picture and a complete, runnable OpenClaw example, see the <a href="https://docs.imposter.sh/websocket_plugin/">WebSocket plugin docs</a>, the <a href="https://docs.imposter.sh/scheduled_tasks/">scheduled tasks docs</a>, and the <a href="https://github.com/imposter-project/examples/tree/main/websocket/openclaw">examples/websocket/openclaw</a> directory in the <a href="https://github.com/imposter-project/examples/">imposter examples repo</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bfd9abfbdbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mocking gRPC Services with Imposter]]></title>
            <link>https://medium.com/@outofcoffee/mocking-grpc-services-with-imposter-dbe2ca8db06f?source=rss-5b8a71ae725------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbe2ca8db06f</guid>
            <category><![CDATA[mocking]]></category>
            <category><![CDATA[quality-software]]></category>
            <category><![CDATA[automation-testing]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[grpc]]></category>
            <dc:creator><![CDATA[Pete Cornish]]></dc:creator>
            <pubDate>Thu, 28 May 2026 14:04:40 GMT</pubDate>
            <atom:updated>2026-05-28T14:04:40.877Z</atom:updated>
            <content:encoded><![CDATA[<p>When a third party service goes down and causes all your integration tests to fail, you realise how brittle this can make your CI/CD pipeline. The same is just as true for gRPC services as for REST or SOAP APIs — and the tooling to mock them has historically been thinner on the ground.</p><p>This post shows how to mock a gRPC service using <a href="https://www.imposter.sh/">Imposter</a> and a Protocol Buffers (.proto) file.</p><h3>A simple service</h3><p>The example mocks a pet store service defined in protobuf, with two RPCs — GetPet and ListPets:</p><pre>syntax = &quot;proto3&quot;;</pre><pre>package store;</pre><pre>service PetStore {<br>  // GetPet returns a single pet by ID.<br>  rpc GetPet (GetPetRequest) returns (GetPetResponse);</pre><pre>  // ListPets returns all pets.<br>  rpc ListPets (ListPetsRequest) returns (ListPetsResponse);<br>}</pre><pre>message GetPetRequest {<br>  int32 id = 1;<br>}</pre><pre>message GetPetResponse {<br>  int32 id = 1;<br>  string name = 2;<br>  string species = 3;<br>}</pre><pre>message ListPetsRequest {}</pre><pre>message ListPetsResponse {<br>  repeated GetPetResponse pets = 1;<br>}</pre><p>Imposter parses the .proto file at startup — there&#39;s no need to run protoc or generate stubs.</p><h3>Configuration</h3><p>The configuration file uses Imposter’s gRPC plugin. Proto files are listed under the config block, and responses are defined using the standard resources block as JSON files:</p><pre># imposter-config.yaml<br>---<br>plugin: grpc<br><br>config:<br>  protoFiles:<br>    - &quot;petstore.proto&quot;<br><br>resources:<br>  - path: &quot;/store.PetStore/GetPet&quot;<br>    response:<br>      file: &quot;get-pet-response.json&quot;<br>  - path: &quot;/store.PetStore/ListPets&quot;<br>    response:<br>      file: &quot;list-pets-response.json&quot;</pre><p>Key points:</p><ul><li>Configuration files must use the -config.yaml suffix.</li><li>protoFiles are resolved relative to the configuration directory.</li><li>The path for each resource is the gRPC method path, in the form /package.Service/Method.</li><li>Response bodies are written as JSON and converted to protobuf wire format automatically using the message descriptors from the .proto file.</li></ul><p>An example get-pet-response.json:</p><pre>{<br>  &quot;id&quot;: 1,<br>  &quot;name&quot;: &quot;Fido&quot;,<br>  &quot;species&quot;: &quot;Dog&quot;<br>}</pre><h3>Starting the mock server</h3><p>The gRPC plugin is an external plugin available in Imposter 5.x. The easiest way to install it is via the <a href="https://docs.imposter.sh/run_imposter_cli/">Imposter CLI</a>. On macOS or Linux you can install the CLI with Homebrew:</p><pre>brew install imposter-project/imposter/imposter</pre><p>Then install the gRPC plugin:</p><pre>imposter plugin install -d grpc -t native</pre><p>This installs the plugin version matching the engine version used by the CLI. Start the mock with:</p><pre>imposter up ./examples/grpc/simple</pre><p>The mock server listens on http://localhost:8080 with HTTP/2 cleartext (h2c), so gRPC clients can connect directly.</p><h3>Testing the mock</h3><p>The simplest way to call the mock is with <a href="https://github.com/fullstorydev/grpcurl">grpcurl</a>.</p><p>Fetch a pet by id:</p><pre>grpcurl -plaintext -proto petstore.proto \<br>  -d &#39;{&quot;id&quot;: 1}&#39; \<br>  localhost:8080 store.PetStore/GetPet</pre><p>Returns:</p><pre>{<br>  &quot;id&quot;: 1,<br>  &quot;name&quot;: &quot;Fido&quot;,<br>  &quot;species&quot;: &quot;Dog&quot;<br>}</pre><p>List all pets:</p><pre>grpcurl -plaintext -proto petstore.proto \<br>  localhost:8080 store.PetStore/ListPets</pre><p>Returns the full list defined in list-pets-response.json.</p><h3>Customising responses</h3><p>Because the gRPC plugin uses Imposter’s core request pipeline, you get request matching, interceptors, capture, steps, scripting and response templating for free.</p><p>For example, you can match on the request body to return a specific response when id=1, and a default response otherwise:</p><pre>resources:<br>  # when id=1, return a specific response<br>  - path: &quot;/store.PetStore/GetPet&quot;<br>    requestBody:<br>      jsonPath: $.id<br>      value: 1<br>    response:<br>      file: &quot;get-pet-response.json&quot;<br><br># default response for this RPC - gRPC NOT_FOUND<br>  - path: &quot;/store.PetStore/GetPet&quot;<br>    response:<br>      statusCode: 5</pre><p>The statusCode field maps directly to gRPC status codes — 5 is NOT_FOUND.</p><h3>Inline responses and templating</h3><p>For small responses, inline JSON content with templating is often the most concise option:</p><pre>resources:<br>  - path: &quot;/store.PetStore/GetPet&quot;<br>    response:<br>      content: &#39;{&quot;id&quot;: 1, &quot;name&quot;: &quot;Fido&quot;, &quot;species&quot;: &quot;Dog&quot;}&#39;<br>      template: true</pre><h3>Summary</h3><p>Imposter parses your .proto files at startup and converts JSON response bodies to protobuf wire format automatically — no codegen or hand-rolled stubs required. Configuration changes need a restart (CTRL+C to stop).</p><p>For full details and more examples, see the <a href="https://docs.imposter.sh/grpc_plugin/">gRPC plugin documentation</a> and the <a href="https://github.com/imposter-project/imposter-go">imposter-go repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbe2ca8db06f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mocking SOAP web services with Imposter]]></title>
            <link>https://medium.com/@outofcoffee/mocking-soap-web-services-with-imposter-da8e9666b5b4?source=rss-5b8a71ae725------2</link>
            <guid isPermaLink="false">https://medium.com/p/da8e9666b5b4</guid>
            <category><![CDATA[web-services]]></category>
            <category><![CDATA[soap]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[mock]]></category>
            <category><![CDATA[tools]]></category>
            <dc:creator><![CDATA[Pete Cornish]]></dc:creator>
            <pubDate>Thu, 10 Feb 2022 00:59:05 GMT</pubDate>
            <atom:updated>2022-02-10T01:25:56.789Z</atom:updated>
            <content:encoded><![CDATA[<p>We all know that integration testing is important. But when a third party service goes down and causes all your integration tests to fail you realise how brittle this can make your CI/CD pipeline. Sometimes you need to isolate yourself and create a <a href="https://martinfowler.com/articles/mocksArentStubs.html">mock</a> of a SOAP web service.</p><blockquote><em>Need a quick mock of a SOAP web service? Say hello to </em><a href="https://www.imposter.sh/"><em>Imposter</em></a><em>.</em></blockquote><blockquote><em>Using OpenAPI/Swagger? Check out the other article: </em><a href="https://medium.com/@outofcoffee/mocking-apis-with-swagger-and-imposter-3694bd1733c0"><em>Mocking APIs with OpenAPI and Imposter</em></a><em>.</em></blockquote><h3>A simple web service</h3><p>Let’s start with a simple web service. In keeping with the rules of the internet, this must involve cats. To keep things simple we’ll define a single endpoint for now, named /pets/ that will return a SOAP message like so:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;env:Envelope xmlns:env=&quot;http://www.w3.org/2001/12/soap-envelope&quot;&gt;<br>    &lt;env:Header/&gt;<br>    &lt;env:Body&gt;<br>        &lt;getPetByIdResponse xmlns=&quot;urn:com:example:petstore&quot;&gt;<br>            &lt;id&gt;3&lt;/id&gt;<br>            &lt;name&gt;string&lt;/name&gt;<br>        &lt;/getPetByIdResponse&gt;<br>    &lt;/env:Body&gt;<br>&lt;/env:Envelope&gt;</pre><p>To represent this web service, we are going to use <a href="https://www.imposter.sh/">Imposter</a>. Imposter is an open source tool for easily creating mocks. In this scenario we will use the <a href="https://docs.imposter.sh/soap_plugin/">SOAP plugin</a>.</p><blockquote><strong><em>Note:</em></strong><em> if you already have a Swagger/OpenAPI specification, you want to use the </em><a href="https://medium.com/@outofcoffee/mocking-apis-with-swagger-and-imposter-3694bd1733c0"><em>OpenAPI plugin</em></a><em> instead.</em></blockquote><h4>The configuration</h4><p>Here is the configuration file for our endpoint:</p><pre># petstore-config.yaml<br>---<br>plugin: soap<br>wsdlFile: petstore.wsdl</pre><blockquote><strong><em>Important: </em></strong><em>Your configuration file must be named with the suffix </em><em>-config.yaml — for example: </em><em>petstore-config.yaml</em></blockquote><p>A few things to call out:</p><ul><li>We are using a WSDL file (petstore.wsdl) containing a simple web service. <a href="https://github.com/outofcoffee/imposter/tree/main/examples/soap/simple"><strong>See the files on GitHub</strong></a></li><li>The WSDL defines the service PetService at the SOAP endpoint /pets/</li><li>It has one operation: getPetById</li><li>A request and response (‘input’ and ‘output’) message is defined using XSD</li></ul><h3>Start the mock</h3><p>Now we’re going to start a mock server that you can call from your client code/web browser/CLI.</p><h4>Preflight checks</h4><ol><li>Ensure you have <a href="https://docs.docker.com/install/">Docker</a> installed and running.</li><li>You should run the command in the next section from the directory containing your WSDL file and Imposter configuration file:</li></ol><pre>$ ls -l<br>-rw-r--r--  1 pete  staff  104 16 Sep 13:55 petstore-config.yaml<br>-rw-r--r--  1 pete  staff  998 16 Sep 13:55 petstore.wsdl</pre><h4>Let’s go!</h4><p>Start the mock server as follows:</p><pre>$ docker run -ti -p 8080:8080 \<br>    -v $PWD:/opt/imposter/config \<br>    outofcoffee/imposter-all</pre><p>You should see log output including the lines:</p><pre>Loading configuration file: /opt/imposter/config/petstore-config.yaml<br>Loaded 1 plugin configuration files from: [/opt/imposter/config]<br>...<br>Adding mock endpoint: tns:SoapBinding -&gt; /pets/<br>Mock engine up and running on <a href="http://localhost:8080/">http://localhost:8080</a></pre><p>Congratulations! 🎉 You now have a working mock server. Let’s test it.</p><h3>Testing your mock</h3><p>Let’s try a test from the command line:</p><p>Send a SOAP request to the /pets/ path defined in the configuration file to see the example response:</p><pre>curl -X POST &quot;http://localhost:8080/pets/&quot; \<br>  -H &#39;Content-Type: application/soap+xml&#39; \<br>  -d &#39;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>  &lt;env:Envelope xmlns:env=&quot;http://www.w3.org/2001/12/soap-envelope&quot;&gt;<br>      &lt;env:Body&gt;<br>          &lt;getPetByIdRequest xmlns=&quot;urn:com:example:petstore&quot;&gt;<br>              &lt;id&gt;3&lt;/id&gt;<br>          &lt;/getPetByIdRequest&gt;<br>      &lt;/env:Body&gt;<br>  &lt;/env:Envelope&gt;&#39;</pre><blockquote>Tip: don’t forget the trailing quote at the end of the string!</blockquote><p>Here is the response:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;env:Envelope xmlns:env=&quot;http://www.w3.org/2001/12/soap-envelope&quot;&gt;<br>    &lt;env:Header/&gt;<br>    &lt;env:Body&gt;<br>        &lt;getPetByIdResponse xmlns=&quot;urn:com:example:petstore&quot;&gt;<br>            &lt;id&gt;3&lt;/id&gt;<br>            &lt;name&gt;string&lt;/name&gt;<br>        &lt;/getPetByIdResponse&gt;<br>    &lt;/env:Body&gt;<br>&lt;/env:Envelope&gt;</pre><p><strong>It works!</strong> Your mock is returning an example SOAP response at the path /pets/, all from Imposter understanding the WSDL file.</p><h4>Customising the response</h4><p>It is often useful to customise the mock response, based on a given input, such as a property of the request. Let’s see how we can customise the payload in the SOAP body.</p><p>We will update our configuration file as follows:</p><pre>plugin: soap<br>wsdlFile: petstore.wsdl</pre><pre>resources:<br>  - operation: getPetById<br>    requestBody:<br>      xPath: &quot;/env:Envelope/env:Body/pets:getPetByIdRequest/pets:id&quot;<br>      value: &quot;3&quot;<br>      xmlNamespaces:<br>        env: &quot;<a href="http://www.w3.org/2001/12/soap-envelope">http://www.w3.org/2001/12/soap-envelope</a>&quot;<br>        pets: &quot;urn:com:example:petstore&quot;<br>    response:<br>      staticFile: getPetByIdResponse.xml</pre><p>Here we have added a configuration entry to look for a particular value in the XML body of the request. If an incoming request matches, Imposter returns the contents of an XML file, getPetByIdResponse.xml, instead of the default response.</p><p>We can test this by re-sending our curl request. This time, the contents of the XML file should be returned. This example illustrates how to use request matching to return a custom response file to control the exact content returned.</p><h4>For completeness</h4><p>The following example shows how you can simulate fault responses. Here, Imposter looks for a value of 99 in the request body and returns an HTTP 500 status code and the contents of a different file, fault.xml .</p><pre># (previous content as above)</pre><pre>  - operation: getPetById<br>    requestBody:<br>      xPath: &quot;/env:Envelope/env:Body/pets:getPetByIdRequest/pets:id&quot;<br>      value: &quot;99&quot;<br>      xmlNamespaces:<br>        env: &quot;<a href="http://www.w3.org/2001/12/soap-envelope">http://www.w3.org/2001/12/soap-envelope</a>&quot;<br>        pets: &quot;urn:com:example:petstore&quot;<br>    response:<br>      staticFile: fault.xml<br>      statusCode: 500</pre><h3>Summary</h3><p>You now have a working mock server. Its endpoints are built from the WSDL file you provided. This means that as your WSDL changes Imposter will keep your mock in sync with the API definition.</p><p>If you update your configuration file or WSDL, just stop/start Imposter to see the changes.</p><blockquote><strong><em>Tip: </em></strong><em>To stop the running mock, just type CTRL+C in its terminal.</em></blockquote><h3>Customising your responses with scripts</h3><p>Imposter is simple to learn, but is also very customisable. If you outgrow returning static example responses from your specification, you can use scripts, written in JavaScript or Groovy, to control the response your mock returns.</p><p>For more information on scripted responses, check out <a href="https://docs.imposter.sh/scripting/">the documentation</a>.</p><h3>Looking for a hosted solution?</h3><p>Do you want to try Imposter, but don’t want to run it yourself? Check out the hosted Imposter service at <a href="https://www.mocks.cloud/"><strong>www.mocks.cloud</strong></a></p><p>It’s free to try!</p><h3>Example code</h3><p>Get the example code <a href="https://github.com/outofcoffee/imposter/tree/main/examples/soap">on GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da8e9666b5b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mocking REST APIs with Imposter]]></title>
            <link>https://medium.com/@outofcoffee/mocking-apis-with-imposter-53bd908632e5?source=rss-5b8a71ae725------2</link>
            <guid isPermaLink="false">https://medium.com/p/53bd908632e5</guid>
            <category><![CDATA[stub]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[rest]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[mock]]></category>
            <dc:creator><![CDATA[Pete Cornish]]></dc:creator>
            <pubDate>Fri, 22 Nov 2019 13:08:47 GMT</pubDate>
            <atom:updated>2022-02-08T14:31:23.770Z</atom:updated>
            <content:encoded><![CDATA[<p>We all know that integration testing is important. But when a third party service goes down and causes all your integration tests to fail you realise how brittle this can make your CI/CD pipeline. Sometimes you need to isolate yourself and create a <a href="https://martinfowler.com/articles/mocksArentStubs.html">mock</a> of an API.</p><blockquote>Need a quick mock of a REST API? Say hello to <a href="https://www.imposter.sh/">Imposter</a>.</blockquote><blockquote><em>Using OpenAPI/Swagger? Check out the other article: </em><a href="https://medium.com/@outofcoffee/mocking-apis-with-swagger-and-imposter-3694bd1733c0"><em>Mocking APIs with OpenAPI and Imposter</em></a><em>.</em></blockquote><h3>A simple API</h3><p>Let’s start with a simple API. In keeping with the rules of the internet, this must involve cats. To keep things simple we’ll define a single endpoint for now, named /cats that will return a JSON array like so:</p><pre>[<br>  {<br>    &quot;id&quot;: 1,<br>    &quot;name&quot;: &quot;Fluffy&quot;,<br>    &quot;type&quot;: &quot;Persian&quot;<br>  },<br>  {<br>    &quot;id&quot;: 2,<br>    &quot;name&quot;: &quot;Leo&quot;,<br>    &quot;type&quot;: &quot;Bengal&quot;<br>  }<br>]</pre><p>To represent this API, we are going to use <a href="https://www.imposter.sh/">Imposter</a>. Imposter is an open source tool for easily creating mocks. In this scenario we will use the built-in <a href="https://docs.imposter.sh/rest_plugin/">REST plugin</a>.</p><blockquote><strong>Note:</strong> if you already have a Swagger/OpenAPI specification, you want to use the <a href="https://medium.com/@outofcoffee/mocking-apis-with-swagger-and-imposter-3694bd1733c0">OpenAPI plugin</a> instead.</blockquote><h4>The configuration</h4><p>Here is the configuration file for our endpoint:</p><pre>---<br>plugin: rest<br>contentType: application/json<br>resources:<br>  - path: &quot;/cats&quot;<br>    response:<br>      staticFile: cats.json</pre><pre>  - path: &quot;/cats/:id&quot;<br>    type: array<br>    response:<br>      staticFile: cats.json</pre><blockquote><strong>Important: </strong>Your configuration file must be named with the suffix -config.yaml — for example: cat-config.yaml</blockquote><p>A few things to call out:</p><ul><li>We’ve defined the endpoint /cats to return the contents of our sample JSON file; in other words an array of cats.</li><li>We’ve also said that, because the response file is a JSON array, we want to allow querying of individual items by their ID, under the /cats/:id endpoint.</li><li>This example assumes you’ve named the file containing your JSON array <em>cats.json</em> and that it is in the same directory as the configuration file.</li></ul><h3>Start the mock</h3><p>Now we’re going to start a mock server that you can call from your client code/web browser/CLI.</p><h4>Preflight checks</h4><ol><li>Ensure you have <a href="https://docs.docker.com/install/">Docker</a> installed and running.</li><li>You should run the command in the next section from the directory containing your JSON sample response file and Imposter configuration file:</li></ol><pre>$ ls -l<br>-rw-r--r--  1 pete  staff  104 16 Sep 13:55 cat-config.yaml<br>-rw-r--r--  1 pete  staff  998 16 Sep 13:55 cats.json</pre><h4>Let’s go!</h4><p>Start the mock server as follows:</p><pre>$ docker run -ti -p 8080:8080 \<br>    -v $PWD:/opt/imposter/config \<br>    outofcoffee/imposter</pre><p>You should see log output including the lines:</p><pre>Loading configuration file: /opt/imposter/config/cat-config.yaml<br>Loaded 1 plugin configuration files from: [/opt/imposter/config]<br>...<br>Adding GET object handler: /cats<br>Adding GET array handler: /cats/:id<br>Mock engine up and running on <a href="http://localhost:8080/">http://localhost:8080</a></pre><p>Congratulations! 🎉 You now have a working mock server. Let’s test it.</p><h4>Testing your mock</h4><p>Let’s try a test from the command line:</p><pre>$ curl &quot;<a href="http://localhost:8443/pets">http://localhost:8080/cats</a>&quot;<br>[<br>  {<br>    &quot;id&quot;: 1,<br>    &quot;name&quot;: &quot;Fluffy&quot;,<br>    &quot;type&quot;: &quot;Persian&quot;<br>  },<br>  {<br>    &quot;id&quot;: 2,<br>    &quot;name&quot;: &quot;Leo&quot;,<br>    &quot;type&quot;: &quot;Bengal&quot;<br>  }<br>]</pre><p><strong>It works!</strong> Your mock is returning the example response at the path /cats along with the HTTP 200 status.</p><h4>Returning single items</h4><p>Because the response file is a JSON array, we can query individual items by their ID, under the /cats/:id endpoint. Let’s try:</p><pre>$ curl &quot;<a href="http://localhost:8080/cats/1">http://localhost:8080/cats/1</a>&quot;<br>{<br>  &quot;id&quot;: 1,<br>  &quot;name&quot;: &quot;Fluffy&quot;,<br>  &quot;type&quot;: &quot;Persian&quot;<br>}</pre><p>Great! A single item from the array 😺</p><p>Because we specified the placeholder :id in the configuration for our array endpoint, Imposter finds the item in the array with the corresponding JSON key (‘id’) and value (‘1’).</p><h3>More than simple APIs</h3><p>Imposter gives you the full range of HTTP methods, as well as the ability to specify custom headers and status codes. Here’s a more advanced example:</p><pre>---<br>plugin: rest<br>path: /example-two<br>contentType: &quot;text/html&quot;<br>method: POST<br>response:<br>  statusCode: 201<br>  headers:<br>    X-Example: &quot;foo&quot;<br>  staticData: |<br>    &lt;html&gt;<br>      &lt;head&gt;<br>        &lt;title&gt;Example&lt;/title&gt;<br>      &lt;/head&gt;<br>      &lt;body&gt;<br>        Hello, world!<br>      &lt;/body&gt;<br>    &lt;/html&gt;</pre><p>Highlights:</p><ul><li>This endpoint will only be accessible via the POST HTTP method</li><li>We’ve indicated that status code 201 should be returned</li><li>We’ve set the content type of the response to HTML</li><li>A custom header will also be returned</li></ul><p>Test this with curl:</p><pre>$ curl -X POST &quot;<a href="http://localhost:8080/example-two">http://localhost:8080/example-two</a>&quot;<br>&lt;html&gt;<br>  &lt;head&gt;<br>    &lt;title&gt;Example&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    Hello, world!<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><h3>Summary</h3><p>You now have a simple mock server. Its endpoints are built from the configuration file you provided. This means that if you add further endpoints, or make changes, Imposter will mock those too.</p><p>If you update your configuration file, just stop/start Imposter to see the changes.</p><blockquote><strong>Tip: </strong>To stop the running mock, just type CTRL+C in its terminal.</blockquote><h3>Customising your responses with scripts</h3><p>Imposter is simple to learn, but is also very customisable. If you outgrow returning static example responses from your specification, you can use scripts, written in JavaScript or Groovy, to control the response your mock returns.</p><p>For more information on scripted responses, check out <a href="https://docs.imposter.sh/scripting/">the documentation</a>.</p><h3>Looking for a hosted solution?</h3><p>Do you want to try Imposter, but don’t want to run it yourself? Check out the hosted Imposter service at <a href="https://www.mocks.cloud/"><strong>www.mocks.cloud</strong></a></p><p>It’s free to try!</p><h3>Example code</h3><p>Get the example code <a href="https://github.com/outofcoffee/imposter/tree/main/examples/rest">on GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53bd908632e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mocking APIs with OpenAPI and Imposter]]></title>
            <link>https://medium.com/@outofcoffee/mocking-apis-with-swagger-and-imposter-3694bd1733c0?source=rss-5b8a71ae725------2</link>
            <guid isPermaLink="false">https://medium.com/p/3694bd1733c0</guid>
            <category><![CDATA[swagger]]></category>
            <category><![CDATA[open-api]]></category>
            <category><![CDATA[mock]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Pete Cornish]]></dc:creator>
            <pubDate>Sun, 16 Sep 2018 23:19:24 GMT</pubDate>
            <atom:updated>2022-02-08T14:31:42.017Z</atom:updated>
            <content:encoded><![CDATA[<p>In our fast moving and API driven world, teams often need to build an API’s client (mobile, web, service) alongside its implementation.</p><p>Smart client developers might agree an API specification with the backend implementation developers. This enables both groups to work simultaneously, and hopefully in a relatively loosely coupled fashion.</p><p>But when testing your client code, a specification document only gets you so far.</p><blockquote>Wouldn’t it be better if your specification was also a live mock of the backend service? Say hello to <a href="https://www.imposter.sh/"><strong>Imposter</strong></a>.</blockquote><h3>A simple specification</h3><p>Let’s start with a simple API. In keeping with the ancient traditions of our people, we will model a pet store. To keep things simple we’ll define a single endpoint for now, named /pets that will return a JSON array like so:</p><pre>[<br>  {<br>    &quot;id&quot;: 101,<br>    &quot;name&quot;: &quot;Cat&quot;<br>  },<br>  {<br>    &quot;id&quot;: 102,<br>    &quot;name&quot;: &quot;Dog&quot;<br>  }<br>]</pre><p>To represent this API, we are going to use <a href="https://github.com/OAI/OpenAPI-Specification">OpenAPI</a> (formerly known as Swagger). This example uses version 2.0 of the specification, but you can use more recent versions too.</p><h4>The specification</h4><p>Here is the Swagger specification for our endpoint:</p><pre>---<br>swagger: &quot;2.0&quot;<br>info:<br>  version: &quot;1.0.0&quot;<br>  title: &quot;Swagger Petstore&quot;<br>consumes:<br>- &quot;application/json&quot;<br>produces:<br>- &quot;application/json&quot;<br>paths:<br>  /pets:<br>    get:<br>      description: &quot;Returns all pets from the system&quot;<br>      produces:<br>        - &quot;application/json&quot;<br>      responses:<br>        &quot;200&quot;:<br>          description: &quot;A list of pets.&quot;<br>          schema:<br>            type: &quot;array&quot;<br>            items:<br>              $ref: &quot;#/definitions/Pet&quot;<br>          examples:<br>            application/json: |-<br>              [<br>                {<br>                  &quot;id&quot;: 101,<br>                  &quot;name&quot;: &quot;Cat&quot;<br>                },<br>                {<br>                  &quot;id&quot;: 102,<br>                  &quot;name&quot;: &quot;Dog&quot;<br>                }<br>              ]<br>definitions:<br>  Pet:<br>    type: &quot;object&quot;<br>    required:<br>      - &quot;id&quot;<br>      - &quot;name&quot;<br>    properties:<br>      id:<br>        type: &quot;integer&quot;<br>        format: &quot;int64&quot;<br>      name:<br>        type: &quot;string&quot;</pre><p>A few things to call out:</p><ul><li>We’ve defined the endpoint /pets as expecting an HTTP GET request</li><li>We’ve said it will produce JSON responses</li><li>One response is defined for the HTTP 200 case</li><li>We’ve defined a basic data model in the definitions section</li><li>We’ve provided an example response — the same JSON array described earlier</li></ul><blockquote><strong>Tip: </strong>There’s much, much more to Swagger than this. Check out <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md">the specification</a> for more info.</blockquote><h4>What’s next?</h4><p>On its own, the specification is a useful way to document and share your API. Let’s take it to the next level with a <a href="https://martinfowler.com/articles/mocksArentStubs.html">mock</a> service based on this specification that you can actually call from your client.</p><h3>Creating a mock</h3><p>All we need to start our mock is a small configuration file. This tells Imposter the name of our Swagger/OpenAPI specification.</p><p>Here’s the configuration file:</p><pre>---<br>plugin: openapi<br>specFile: petstore.yaml</pre><blockquote><strong>Note: </strong>This assumes you’ve named your specification petstore.yaml and that it is in the same directory as your configuration file.</blockquote><p><strong>Important: </strong>Your configuration file must be named with the suffix -config.yaml — for example: petstore-config.yaml</p><h4>Preflight check</h4><ol><li>Ensure you have <a href="https://www.docker.com/">Docker</a> installed and running.</li><li>You should run the command in the next section from the directory containing your Swagger/OpenAPI specification and Imposter configuration file:</li></ol><pre>$ ls -l<br>-rw-r--r--  1 pete  staff  104 16 Sep 13:55 petstore-config.yaml<br>-rw-r--r--  1 pete  staff  998 16 Sep 13:55 petstore.yaml</pre><h4>Start the mock</h4><p>You can start the mock server as follows:</p><pre>docker run -ti -p 8080:8080 \<br>    -v $PWD:/opt/imposter/config \<br>    outofcoffee/imposter</pre><p>You should see log output including the lines:</p><pre>Loading configuration file: /opt/imposter/config/petstore-config.yaml<br>Loaded 1 plugin configuration files from: [/opt/imposter/config]<br>...<br>reading from /opt/imposter/config/petstore.yaml<br>Adding mock endpoint: GET -&gt; /pets<br>Mock engine up and running on <a href="http://localhost:8080/">http://localhost:8080</a></pre><p>Congratulations! 🎉 You now have a working mock server. Let’s test it.</p><h4>Testing your mock</h4><p>Let’s try a test from the command line:</p><pre>$ curl -X GET &quot;<a href="http://localhost:8443/pets">http://localhost:8080/pets</a>&quot;<br>[<br>  {<br>    &quot;id&quot;: 101,<br>    &quot;name&quot;: &quot;Cat&quot;<br>  },<br>  {<br>    &quot;id&quot;: 102,<br>    &quot;name&quot;: &quot;Dog&quot;<br>  }<br>]</pre><p><strong>It works!</strong> Your mock is returning the example response from your specification at the path /pets along with the HTTP 200 status.</p><h4>Exploring the mock</h4><p>To explore your mock, visit the UI at: <a href="http://localhost:8443/_spec/">http://localhost:8080/_spec/</a><br>This will show you a page that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*YGPbi97cs3H9ezMaOunTig.png" /><figcaption>Imposter showing the Swagger UI for an API specification</figcaption></figure><h3>Summary</h3><p>You now have a simple mock server. Its endpoints are built automatically from your OpenAPI specification. This means that if you add further endpoints, or make changes, Imposter will mock those too.</p><p>If you update your specification file, just stop/start Imposter to see the changes.</p><blockquote><strong>Tip: </strong>To stop the running mock, just type CTRL+C in its terminal.</blockquote><h3>Customising your responses with scripts</h3><p>Imposter is simple to learn, but is also very customisable. If you outgrow returning static example responses from your specification, you can use scripts, written in JavaScript or Groovy, to control the response your mock returns.</p><p>For more information on scripted responses, check out <a href="https://docs.imposter.sh/scripting/">the documentation</a>.</p><h3>Looking for a hosted solution?</h3><p>Do you want to try Imposter, but don’t want to run it yourself? Check out the hosted Imposter service at <a href="https://www.mocks.cloud/"><strong>www.mocks.cloud</strong></a></p><p>It’s free to try!</p><h3>Example code</h3><p>Get the example code <a href="https://github.com/outofcoffee/imposter/tree/main/examples/openapi">on GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3694bd1733c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>