Mock Open API endpoints that haven‘t been implemented yet? - api

Mocking endpoints an Open API Specification file defines isn't all that difficult.
However I am trying to mock only the endpoints that don't have an implementation yet.
For example I have an OAS file that defines an GET /dogs and an GET /cats endpoint.
Now when I implement GET /dogs in a - for example - Nest.js application and that application is running, I would want to have a mock server that only mocks the GET /cats endpoint.
That would make it possible to bundle the mock server and the application and to deploy them together, so that some form of response (either the implementation or the mocked) is always returned for every endpoint.
Is there some sort of tool/mock-server that has this kind of ability? Would doing something like that even make sense?

Related

How to load testing an application that calling external service APIs using Jmeter?

I currently want to perform a load testing an application using Jmeter but some functions need to call an external service APIs.
So I want to know how do I test those APIs without the app calling the actual external API service.
For example, I want to test an application that calling Google Maps Platform Directions API to get a direction from point A to B.
There is a concept of Mock Object, you can configure your application to point to your own external API implementation instead of Directions API which will return static or random or pre-defined response.
One of possible options is using i.e. Wiremock for this, you can interact with Wiremock REST API using JMeter's HTTP Request samplers to create/amend mock responses on the fly.

Using Karate, can the .feature Mock files intercept calls from back-end Java service class?

Question about Karate: can the .feature Mock files intercept calls from back-end Java service class?
I think the mocking feature is pretty easy to understand. I can see that you can start the mock server in the background step and then your scenario HTTP calls will be intercepted BUT
My question is: is it possible to intercept HTTP calls coming from my back-end service class after I hit my API endpoint with a Karate step?
If I don't get an answer, I will put together a sample project and experiment. Just hoping someone knows off-hand. If not, I think I can probably run an instance of Mountebank.
It may be possible by telling the JVM to use an HTTP proxy, but it depends a lot on the system under test.
You can find more details here: https://stackoverflow.com/a/61414022/143475

How to build a facade of an existing service in IBM API Connect?

To get started quickly with API Connect, I just want to import a Swagger spec of an existing service and make this service a managed API in API Connect.
API Connect provides an import function for YAML files, but the API can not be tested.
I've seen this scenario several times, so I though it might be useful to have some documentation on this.
When importing a swagger specification, you need to modify a few settings to transform this service definition into an API definition (even though they are quite similar). You need to modify the following parameters:
Schemes https - The Gateway enforces HTTPS
Host: $(catalog.host) - This variable links to the current host (in a certain catalog)
Then, you need to build an assembly. The proxy policy is well suited for building facades, as all content from Headers, Body, etc. is re-routed. For the URL, enter the URL of the endpoint + a context variable that refers to the incoming path, like:
http://example.com$(request.path)
I have created a small video on Youtube to demonstrate the neccessary steps.

calling rest api from another web application

I have a web application (typical mvc webapp) that needs to call a REST API bundled in a different webapp (war file).
The first web app serves as a front to the separate REST API webapp for customers to register and view their stats, purchase plans etc. But part of the design of this webapp is that it must have example invocations to the other REST API webapp.
There are many rest clients out there, but what would be a reasonable approach to address the above?
I was thinking of using the Spring REST Template to call the REST API but from my mvc controller class in the first webapp. Is this a reasonable approach?
Once you deploy a webapp using your deployment tool of choice, you can simply call the REST URL. That's one of the great things about REST - it doesn't care about what sort of tool is calling it because it deals in a neutral medium (usually HTTP). Twitter's REST API (here) doesn't care what's calling it - in fact the beauty of it is that anyone can make an app that calls it.
So say you deployed a webapp locally to port 8080, you can just make a REST call to http://localhost:8080/firstapp/rest/foo.
If you're deployed to the World Wide Web, then just call the appropriate domain.
Yes, RestTemplate is a very convenient way for server to server REST calls. Though there are some tricks if you are going to serialize generics.

How to setup spring.net dependency injection for a web service?

I have been handed a wsdl file + a number of xsd type definition files - the service I need to code against is not ready yet and I need to put together a fake service (so called a stub or mock) in order to be ready when the real thing comes along.
My question is - once I get the interface I need to implement from the wsdl, how do I setup dependency injection so that whenever the new service comes along I can add a service reference or a web reference and just edit the spring.net config file to swap in the service I want in the consumer? Is it even possible?
I found this article, specific to WCF, It's pretty good but he seems to have access to the service code and he's doing dependency injection on the service side rather than on the consumer side - in my case I will most likely just get a url, I will have to swap it with the fake local one and go from there.
Also is there a way of doing this only dependent on the way I consume the service but not on the way the service was put together? I mean, I shouldn't care less which technology was used to develop the service as long as I get a url to the wsdl.
Any pointers appreciated!
Just create an interface which maps to the webservice methods and use that on the client side. It doesn't matter if it's a local service, webservice, or whatever.
I've done what you are trying to do before, you can read about it here.