<?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 Tobias Becker on Medium]]></title>
        <description><![CDATA[Stories by Tobias Becker on Medium]]></description>
        <link>https://medium.com/@tobiasbe?source=rss-97ad5f9aad7a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_NYkqDF_zn_zt9fcx2g37A.png</url>
            <title>Stories by Tobias Becker on Medium</title>
            <link>https://medium.com/@tobiasbe?source=rss-97ad5f9aad7a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 19:52:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tobiasbe/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[Backend Mock To Go: Swagger meets Node.JS and AWS Beanstalk]]></title>
            <link>https://medium.com/intive-developers/backend-mock-to-go-swagger-meets-node-js-and-aws-beanstalk-5f771cc1901?source=rss-97ad5f9aad7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f771cc1901</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[swagger]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[mocking]]></category>
            <dc:creator><![CDATA[Tobias Becker]]></dc:creator>
            <pubDate>Mon, 10 Sep 2018 15:04:09 GMT</pubDate>
            <atom:updated>2018-09-11T10:54:59.561Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yOwrqvYRScw-qJw7sKIZXA.png" /></figure><p>Sometime you just need a mock backend for the frontend you’re building. And you need it right now. At least this is what happened in one of my latest projects right after we started to build the frontend.</p><p>It was a completely new product, which means that the backend we should work with was just being designed at the time we had to start building the first features. After only two sprints, we had reached the point where further development without having a backend would just be building workarounds and non-testable features. Fortunately, we already had agreed on an API with the backend development team.</p><p>In this post i want to walk you through all the steps necessary to create and host a very basic mock backend in just 15 minutes. The mock will be able to serve static JSON content and validate input based on a swagger definition and its example values.</p><p>What we will cover in this walkthrough:</p><ol><li>Revisit our use case and justify this is the right way to mock</li><li>Generate a Node.js mock from a swagger specification</li><li>Host our mock on AWS Elastic Beanstalk</li></ol><h3>What we need and why</h3><p>In the <a href="https://medium.com/intive-developers/backend-mocking-an-overview-ca0cc3485c6c">first story of this series</a>, we already learned about the reasons for creating a mock and about what to consider regarding availability, functionality, flexibility, and effort.</p><p>Let’s apply what we learned to our specific use case and double check if using Swagger-codegen and AWS Beanstalk is a good fit for us.</p><p><strong>Availability</strong>: We need our mock to be available for developers, testers, and product owners.</p><p><em>→ We need to host the mock online. This makes AWS a reasonable choice.</em></p><p><strong>Functionality:</strong> The final backend will validate the requests’ input, so the mock should do the same. That way, we can minimize the risk of issues when migrating from our mock to the final backend. We also know that we do not need to keep any state in our mock.</p><p><em>→ We want input to be validated, content can be served from static JSON files since we don’t need any state.</em></p><p><strong>Flexibility:</strong> The API is agreed on and it is defined in swagger format. We don’t expect any changes in the API itself. The data being served by the mock should be easy to change though.</p><p><em>→ The API code can be generated once. The JSON data it serves should be easy to update.</em></p><p><strong>Effort / Cost:</strong> Our frontend team is already blocked, so the mock has to be ready as soon as possible. Cost for hosting is not an issue.</p><p><em>→ Generating our mock code is fast, we only need a way to quickly host it.</em></p><p><strong>Conclusion</strong>:<br>Since we have the API specified in Swagger format, we can use swagger-codegen to generate the mock in almost every programming language we want. This gives us a functional mock which out of the box validates input based on the schemas in our API definition. The example values in the definition are automatically translated into JSON objects which can be updated easily. AWS Beanstalk is a quick and straightforward way to host web apps. It allows us to have the mock up and running in only a few minutes.</p><h3>Creating the Mock</h3><p>For this tutorial, let’s use a very basic sample API that contains some input validation. The mock will contain:</p><ul><li>GET /user/{user_id}</li><li>POST /user</li></ul><p>You can find a sample swagger definition in the file user-api.yml in this repository: <a href="https://github.com/tobiasbe/backend-mock-beanstalk">https://github.com/tobiasbe/backend-mock-beanstalk</a></p><p>If you want to skip the steps necessary to generate the mock’s code and jump right to the deployment step, you can do so. Just clone the whole repository and change directory to user-mock. It contains a ready-to-use mock server based on our user-api.yaml example.</p><h4><strong>Generate the Code</strong></h4><p>In order to generate our mock code, we will user swagger’s official swagger-codegen project. It only takes us a few steps to download, build and run.</p><p>To get started, download the API definition from the above-mentioned repository and save it in your working directory. Once that’s done, execute the steps below. If you already have swagger-codegen installed, you can skip lines 1–4.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44aa20207bc75347afa6b8d846bbca94/href">https://medium.com/media/44aa20207bc75347afa6b8d846bbca94/href</a></iframe><p>The user-mock directory should now contain a NodeJS project that is ready to be run locally.</p><p><strong>Important</strong>: In order to make the generated code compatible with how Beanstalk runs Node.js projects, we need to remove the “prestart” script from the package.json file.</p><pre>// before<br>&quot;scripts&quot;: {<br>  &quot;prestart&quot;: &quot;npm install&quot;,  // remove me, please<br>  &quot;start&quot;: &quot;node index.js&quot;<br>},</pre><pre>// after<br>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;node index.js&quot;<br>}</pre><h4><strong>Run and Test the Mock locally</strong></h4><pre>cd user-mock<br>npm install<br>npm start</pre><p>This will install all necessary dependencies and run the mock server on port 8081. Use your browser and navigate to: <a href="http://localhost:8001/docs">http://localhost:8081/docs</a> to see your API’s Swagger UI and try out the requests.</p><p>Whenever you send a request using Swagger UI or manually via cURL, one of the functions in $(Project_Root)/services/UsersService.js is being called. This is the place where you can modify the mock’s behavior. We could, for example, remove the sample data from the getUserById function and instead add a static JSON file with a list of users that can be used to find users by id and return a 404 in case the requested user does not exist.</p><p>Earlier, I mentioned that the data you send to the endpoints will be validated. Validation is handled by the swagger middleware which is configured in index.js. It validates all incoming requests based on the swagger specification before routing them to the respective controllers. If you would now send a POST request to /users containing a JSON object without the fields name and avatar, the mock would reject it.</p><h3>Deploying the Mock</h3><p>Since we chose AWS Elastic Beanstalk for hosting, we first of all need an AWS Account. In our account we will create an IAM user which we can then use to create our Elastic Beanstalk environment.</p><h4>Set up your Account</h4><p>If you do not have an AWS Account yet, create one. The process is pretty straightforward and well explained. After creating your account, you will have root access to it. Even though you could use your root account to complete all of our following steps, it is best practice to create an IAM user which only has the permissions necessary to do so.</p><h4>Create a suitable IAM User</h4><p>To create an IAM user, log in to the AWS console using your root account and select IAM from the list of services. In the “Users” tab, you can choose to create a new user. Supply a username and make sure to at least tick the box for “Programmatic Access”. When asked to assign permissions, choose “Attach existing policies directly” and select “AWSElasticBeanstalkFullAccess” from the list. In the last step of the process, make sure to save both the <br>Access Key ID and the Secret Access Key, since you will not be able to access the secret key later.</p><h4>Set up your Beanstalk Application</h4><p>Before starting this step, you need to have the AWS Elastic Beanstalk CLI installed on your machine. You can find the installation instructions <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html">here</a>.</p><p>After installing the EB CLI, initialize your Beanstalk application by running the following command from within your user-mock directory:</p><pre>eb init</pre><p>This will ask you for a couple of things:</p><ol><li>A region to host your application in<br> → Up to you. I went with “eu-central-1”</li><li>Your AWS Access Key ID + Secret Access Key<br> → Use the values you got when creating your IAM user</li><li>Use an existing application or create a new one<br> → We want to create a new one</li><li>Enter an application name<br> → Enter whatever you want the name to be</li><li>Confirm that you are using Node.js or to select a platform<br> → In case you have to select a platform, choose Node.js</li><li>If you want to use CodeCommit<br> → For this tutorial, AWS CodeCommit is not needed</li></ol><h4>Create your Beanstalk environment</h4><p>In our next step, we will create an Elastic Beanstalk environment and upload the first version of our mock by running: (this can take a few moments)</p><pre>eb create dev-mock-env</pre><p><em>Note: If you run into any permission errors in this step, make sure you are using the latest version of the EB CLI.</em></p><p>If you did not get any errors, your application should now be running and you can access it by running:</p><pre># Open your application in your default browser<br>eb open</pre><p>This should open the mock application in your default browser. As earlier, adding /docs to the URL brings you to Swagger UI. Adding /api/v1/user/0 to the URL will return the dummy user from UserService.js.</p><p>In case you run into any errors or see error pages, viewing the logs of your application might be helpful. You can view them using the AWS console in your browser or by simply running</p><pre># Get the most recent logs right into your terminal<br>eb logs</pre><pre># Open your application in the AWS Elastic Beanstalk Console<br>eb console</pre><p>That’s it. You’ve managed to create a mock backend and host it within approximately 15 minutes. Wasn’t that easy?</p><p>Last but not least, let me show you how you can clean up all the resources you’ve created during this walkthrough:</p><pre># Terminate and clean up the environment<br>eb terminate dev-mock-env</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f771cc1901" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intive-developers/backend-mock-to-go-swagger-meets-node-js-and-aws-beanstalk-5f771cc1901">Backend Mock To Go: Swagger meets Node.JS and AWS Beanstalk</a> was originally published in <a href="https://medium.com/intive-developers">intive Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Backend Mocking — An overview]]></title>
            <link>https://medium.com/intive-developers/backend-mocking-an-overview-ca0cc3485c6c?source=rss-97ad5f9aad7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca0cc3485c6c</guid>
            <category><![CDATA[mocking]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Tobias Becker]]></dc:creator>
            <pubDate>Tue, 24 Jul 2018 11:34:01 GMT</pubDate>
            <atom:updated>2018-07-24T11:34:01.862Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Ppgf5MKvaIcxsMWxPboWQ.png" /></figure><p>You have your project environment set up, you started to build the first set of features — but then, suddenly, you are blocked by a nonexistent backend. As a web or mobile frontend developer, it’s likely that you have encountered this situation at least once.</p><p>One way out of this misery is using backend mocks. In this article, I want to give a short overview of motivations for building backend mocks, what alternatives you have for building those and what you need to consider when choosing the correct strategy for your project.</p><h3><strong>Why mock backend functionality?</strong></h3><p>In my current project, we are building an iOS and an Android app for a brand new product. At the time of the kickoff, our client just started working on the whole project’s setup, so there was - of course - no backend implemented yet.</p><p>That is why we sat down with both, the frontend and backend development teams right at the start of the project. After a few iterations, we agreed on the API’s design, so the backend team could start implementing it.</p><p>Since that point in time, the frontend team already was ahead of the backend team by quite a bit, we decided to build a mock backend ourselves. This would enable the frontend teams to continue working on features and the QA team to test the frontends without being blocked by missing backend services.</p><p>In general, i would recomment to mock backend functionality when you face a combination of the following circumstances:</p><ul><li>The frontend team is ahead in feature development</li><li>Further development can’t wait for the backend to be ready</li><li>Your QA team relies on actual working features for testing</li><li>The backend team building a mock would cost even more time</li></ul><h3><strong>What you need to consider</strong></h3><p><em>Make sure you have a well-aligned API before starting to mock since every change means that the mock needs to be updated.</em></p><p>As we already had agreed on what the API would look like and on how the mobile clients would use it, we could take the next step: Find out which requirements we have for the mock.</p><p>If you want to build a mock for your team, you have a whole lot of options, but not all of them will meet your requirements. When gathering your requirements, you should consider the following topics:</p><ul><li><em>Availability</em>: Do you need the mock outside of your development environment?</li><li><em>Functionality</em>: Do you need input validation?</li><li><em>Flexibility</em>: Do you need the mock to be easy to update?</li><li><em>Effort</em>: How much time do you want to invest?</li></ul><p>Having those four topics in mind, we sat down for a short meeting and collected the following requirements for our project:</p><p>1. Both iOS and Android need the same data and behavior<br>2. The mock needs to be accessible via mobile internet for testing<br>3. The mock needs to be able to validate request headers + body<br>4. It must be easy to modify data for demo and testing purposes<br>5. We need the mock to be ready within a couple of hours</p><h3><strong>Your Options</strong></h3><p>If you google for backend mocks, you will find a ton of options. There are simple and straightforward options, more flexible ones, paid services and of course, you can build your own custom solution. Depending on your specific requirements you might end up choosing a different approach on different projects.</p><p>Some of the most prominent options are:</p><ul><li>Mocking in frontend code</li><li>Serving data using plain JSON files (local or online)</li><li>Running a local mock server on developer machines</li><li>Using Paid services</li><li>Hosting your own code in the cloud</li></ul><p><strong>Options vs. Requirements</strong></p><p>Let’s now have a second look at the topics from above in combination with our requirements and see what their implications on our options are.</p><p><strong>Availability:</strong> Local or cloud?</p><p>Hosting a local mock server on your developer machine can be a quick win, but usually, it’s not the best choice for bigger teams. Especially if your QA team also needs access to the same mock, you’ll either have to mock in your code (with double the effort if you build for two platforms) or host your mock somewhere in the cloud. In our case, we even needed the mock to be available on the go, so we decided to go with the cloud path.</p><p><strong>Functionality:</strong> Basic or complex?</p><p>If you only need to support simple GET requests, using some JSON files in the code or on AWS S3 might do the trick for you, but what if you need input validation or even want to build in some test scenarios for your QA people? Well, then you might be better off with hosting a mock-server that can execute at least some logic. Since we wanted our mock to be as close to the final API as possible, we went with an option that would allow us to validate both HTTP headers and bodies.</p><p><strong>Flexibility:</strong> Static or updateable?</p><p>In case you’ve already decided to host a mock either locally on your machine or in the cloud, you still have choices. API documentation in Swagger allows you to generate a mock server using swagger-codegen. But, if you need to add custom data to your mock and be able to update the interface, you might end up replacing your custom data with the newly generated code. In our project we reached this point, so we decided to upgrade to a completely custom NodeJS-based mock.</p><p><strong>Effort:</strong> How much time do you have?</p><p>Even if you would like to build the most flexible and powerful mock, the resources you have at hand to do so are most likely limited. If you need a somewhat advanced mock but are not in the position to build a custom one, a paid cloud solution might be worth a look.</p><h3><strong>Conclusion</strong></h3><p>Building a mock backend for our mobile frontends was the one best thing we could have done at the very beginning of the project. It unblocked the frontend teams immediately, allowing them to build a large part of the app before the first backend services were online.</p><p>However, choosing the right approach for mocking requires some thinking and careful consideration of four important factors: Availability, Functionality, Flexibility, and Effort.</p><p>After you have sat down and clarified your requirements, make sure your API design is final because otherwise, every change will require an update of your mock.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca0cc3485c6c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intive-developers/backend-mocking-an-overview-ca0cc3485c6c">Backend Mocking — An overview</a> was originally published in <a href="https://medium.com/intive-developers">intive Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>