Search code examples
androidhttprestful-authentication

Generate mock service as HTTP endpoint


I am using this example login to build the RESTful part in my application. However, I do not have a server connected. What I want to do is to create a mock service, using an HTTP generator as Mocky (check it). Does anyone know how can this be achieved? Thanks a lot!


Solution

  • Sorry for being so long to answer (little bit busy that week). Well, I hope you haven't given up meanwhile...

    So below is the procedure to set up a RESTful mock service :

    1. You can download the Opensource version of SOAP UI here. It's enough for making a simple mock service

    2. Create a new empty Project

    3. Right click on the project and click on "New REST mock service"

    4. Right click on MockService1 and click on "Add new mock action" enter image description here

    enter image description here

    1. Then double-click on /api/v1/user and Add a new mock response (right-click / New Mock response) enter image description here

    2. It's done. You just need to double-click on "REST MockService1" and run the service (green button)

    enter image description here

    You can configure the path, port and host : enter image description here

    Once running, you're WebService can be called using this HTTP Request : GET http://localhost:8080/api/v1/users

    Much more information on the WebSite : https://www.soapui.org/rest-testing-mocking/rest-service-mocking.html You can for example, define some algorithmes to make your webservice more intelligent and test every case (for example if user is = 1 return 200 OK {user} otherwise return 404 ERROR NOT FOUND, ...)