You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
}</script><!-- End Schema.org --></head><bodydata-id="getting-started" data-main-title="Getting-started" data-article-props="{"seeAlsoStyle":"links"}" data-template="article" data-breadcrumbs="" data-edit-url="https://github.com/apollographql/apollo-kotlin-mockserver/edit/main/Writerside/topics/getting-started.md"><divclass="wrapper"><mainclass="panel _main"><headerclass="panel__header"><divclass="container"><h3>Apollo Kotlin MockServer Help</h3><divclass="panel-trigger"></div></div></header><sectionclass="panel__content"><divclass="container"><articleclass="article" data-shortcut-switcher="inactive"><h1data-toc="getting-started" id="getting-started.md">Getting-started</h1><pid="goh78j_3">Apollo MockServer is a <ahref="https://kotlinlang.org/docs/multiplatform.html" id="goh78j_16" data-external="true" rel="noopener noreferrer">KMP</a> server for your HTTP and WebSocket tests.</p><pid="goh78j_4"><spanclass="control" id="goh78j_17">Features:</span></p><ulclass="list _bullet" id="goh78j_5"><liclass="list__item" id="goh78j_18"><p>Enqueue mocked HTTP responses</p></li><liclass="list__item" id="goh78j_19"><p>Dequeue recorded HTTP requests</p></li><liclass="list__item" id="goh78j_20"><p>Enqueue mocked WebSocket messages</p></li><liclass="list__item" id="goh78j_21"><p>Dequeue recorded WebSocket messages</p></li><liclass="list__item" id="goh78j_22"><p>JVM, Native and JS (Node) support</p></li></ul><pid="goh78j_6">Apollo MockServer was initially developed for <ahref="https://github.com/apollographql/apollo-kotlin/" id="goh78j_23" data-external="true" rel="noopener noreferrer">Apollo Kotlin</a> integration tests and is provided as-is to the community.</p><pid="goh78j_7">Performance and compatibility are minimal. Do not use in production.</p><pid="goh78j_8"><spanclass="control" id="goh78j_24">Non-goals:</span></p><ulclass="list _bullet" id="goh78j_9"><liclass="list__item" id="goh78j_25"><p>HTTP2/HTTP3</p></li><liclass="list__item" id="goh78j_26"><p>HTTPS/TLS</p></li><liclass="list__item" id="goh78j_27"><p>Performance</p></li></ul><pid="goh78j_10">Should a future version of <ahref="https://ktor.io/docs/server-platforms.html" id="goh78j_28" data-external="true" rel="noopener noreferrer">Ktor</a> or any other server framework provide a <codeclass="code" id="goh78j_29">commonMain</code> API, Apollo Kotlin MockServer would probably become deprecated.</p><pid="goh78j_11">In the meantime, add the dependency to your project and enjoy cross-platform integration tests!</p><divclass="code-block" data-lang="none">
16
+
}</script><!-- End Schema.org --></head><bodydata-id="getting-started" data-main-title="Getting-started" data-article-props="{"seeAlsoStyle":"links"}" data-template="article" data-breadcrumbs="" data-edit-url="https://github.com/apollographql/apollo-kotlin-mockserver/edit/main/Writerside/topics/getting-started.md"><divclass="wrapper"><mainclass="panel _main"><headerclass="panel__header"><divclass="container"><h3>Apollo Kotlin MockServer Help</h3><divclass="panel-trigger"></div></div></header><sectionclass="panel__content"><divclass="container"><articleclass="article" data-shortcut-switcher="inactive"><h1data-toc="getting-started" id="getting-started.md">Getting-started</h1><pid="fkv9dk_3">Apollo MockServer is a <ahref="https://kotlinlang.org/docs/multiplatform.html" id="fkv9dk_16" data-external="true" rel="noopener noreferrer">KMP</a> server for your HTTP and WebSocket tests.</p><pid="fkv9dk_4"><spanclass="control" id="fkv9dk_17">Features:</span></p><ulclass="list _bullet" id="fkv9dk_5"><liclass="list__item" id="fkv9dk_18"><p>Enqueue mocked HTTP responses</p></li><liclass="list__item" id="fkv9dk_19"><p>Dequeue recorded HTTP requests</p></li><liclass="list__item" id="fkv9dk_20"><p>Enqueue mocked WebSocket messages</p></li><liclass="list__item" id="fkv9dk_21"><p>Dequeue recorded WebSocket messages</p></li><liclass="list__item" id="fkv9dk_22"><p>JVM, Native and JS (Node) support</p></li></ul><pid="fkv9dk_6">Apollo MockServer was initially developed for <ahref="https://github.com/apollographql/apollo-kotlin/" id="fkv9dk_23" data-external="true" rel="noopener noreferrer">Apollo Kotlin</a> integration tests and is provided as-is to the community.</p><pid="fkv9dk_7">Performance and compatibility are minimal. Do not use in production.</p><pid="fkv9dk_8"><spanclass="control" id="fkv9dk_24">Non-goals:</span></p><ulclass="list _bullet" id="fkv9dk_9"><liclass="list__item" id="fkv9dk_25"><p>HTTP2/HTTP3</p></li><liclass="list__item" id="fkv9dk_26"><p>HTTPS/TLS</p></li><liclass="list__item" id="fkv9dk_27"><p>Performance</p></li></ul><pid="fkv9dk_10">Should a future version of <ahref="https://ktor.io/docs/server-platforms.html" id="fkv9dk_28" data-external="true" rel="noopener noreferrer">Ktor</a> or any other server framework provide a <codeclass="code" id="fkv9dk_29">commonMain</code> API, Apollo Kotlin MockServer would probably become deprecated.</p><pid="fkv9dk_11">In the meantime, add the dependency to your project and enjoy cross-platform integration tests!</p><divclass="code-block" data-lang="none">
</div><sectionclass="chapter"><h2id="enqueuing-mock-responses" data-toc="enqueuing-mock-responses">Enqueuing mock responses</h2><pid="fkv9dk_30">To enqueue responses, use <codeclass="code" id="fkv9dk_33">MockServer.enqueue</code>:</p><divclass="code-block" data-lang="kotlin">
20
20
// .use {} makes sure to release the resources at the end of the test
21
21
MockServer().use { mockServer ->
22
22
mockServer.enqueue(
@@ -28,7 +28,7 @@
28
28
29
29
// You can enqueue multiple responses if needed
30
30
}
31
-
</div><asideclass="prompt" data-type="note" data-title="" id="goh78j_32"><pid="goh78j_34"><codeclass="code" id="goh78j_35">MockServer</code> holds resources and must be closed after use. <codeclass="code" id="goh78j_36">.use {}</code> does it automatically.</p></aside></section><sectionclass="chapter"><h2id="reading-recorded-requests" data-toc="reading-recorded-requests">Reading recorded requests</h2><pid="goh78j_37">Use <codeclass="code" id="goh78j_39">MockServer.awaitRequest()</code> to retrieve a recorded request that you can assert to check the behaviour of your client code.</p><divclass="code-block" data-lang="kotlin">
31
+
</div><asideclass="prompt" data-type="note" data-title="" id="fkv9dk_32"><pid="fkv9dk_34"><codeclass="code" id="fkv9dk_35">MockServer</code> holds resources and must be closed after use. <codeclass="code" id="fkv9dk_36">.use {}</code> does it automatically.</p></aside></section><sectionclass="chapter"><h2id="reading-recorded-requests" data-toc="reading-recorded-requests">Reading recorded requests</h2><pid="fkv9dk_37">Use <codeclass="code" id="fkv9dk_39">MockServer.awaitRequest()</code> to retrieve a recorded request that you can assert to check the behaviour of your client code.</p><divclass="code-block" data-lang="kotlin">
32
32
// .use {} makes sure to release the resources at the end of the test
33
33
MockServer().use { mockServer ->
34
34
mockServer.enqueue(...)
@@ -42,4 +42,4 @@
42
42
// ...
43
43
}
44
44
}
45
-
</div></section><sectionclass="chapter"><h2id="next-steps" data-toc="next-steps">Next steps</h2><pid="goh78j_40">Take a look at the <ahref="recipes.html" id="goh78j_41" data-tooltip="Recipes mockServer.enqueueString( string = "{\"status\":200}", contentType = "application/json" ) mockServer.enqueueError(500) mockServer.enqueueMultipart( partsContentType = "application/json" ).apply { enqueuePart("{\"part\":…">Recipes</a> or <ahref="websockets.html" id="goh78j_42" data-tooltip="Apollo Kotlin MockServer supports WebSockets">WebSockets</a> pages to learn more.</p></section><divclass="last-modified">Last modified: 19 July 2024</div><divdata-feedback-placeholder="true"></div><divclass="navigation-links _bottom"><ahref="recipes.html" class="navigation-links__next">Recipes</a></div></article><divid="disqus_thread"></div></div></section></main></div><scriptsrc="https://resources.jetbrains.com/writerside/apidoc/6.10.0-b408/app.js"></script></body></html>
45
+
</div></section><sectionclass="chapter"><h2id="next-steps" data-toc="next-steps">Next steps</h2><pid="fkv9dk_40">Take a look at the <ahref="recipes.html" id="fkv9dk_41" data-tooltip="Recipes mockServer.enqueueString( string = "{\"status\":200}", contentType = "application/json" ) mockServer.enqueueError(500) mockServer.enqueueMultipart( partsContentType = "application/json" ).apply { enqueuePart("{\"part\":…">Recipes</a> or <ahref="websockets.html" id="fkv9dk_42" data-tooltip="Apollo Kotlin MockServer supports WebSockets">WebSockets</a> pages to learn more.</p></section><divclass="last-modified">Last modified: 19 July 2024</div><divdata-feedback-placeholder="true"></div><divclass="navigation-links _bottom"><ahref="recipes.html" class="navigation-links__next">Recipes</a></div></article><divid="disqus_thread"></div></div></section></main></div><scriptsrc="https://resources.jetbrains.com/writerside/apidoc/6.10.0-b408/app.js"></script></body></html>
0 commit comments