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

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.

Related

Mock Open API endpoints that havenā€˜t been implemented yet?

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?

How to allow access to subset of API only when connected via my official frontend, using Nest.js?

I'm starting a Nest.js API, and a subset of my API is business critical. I don't want it accessible openly via HTTP(S), except if the request is coming from my website. Other APIs might instead by accessible with whatever third-party client.
Is there a way to achieve this using Nest.js?

Semantics3 API with AngularJS Authentication

I am in the process of learning AngularJS. I am building a mobile first application using bootstrap 3.1.0.
Basically I want to consume the Semantics3 API and display the products in a list. How can I do this when Semantics3's API needs authentication via OAuth. I already have my API key and secret, but I do not know how to successfully make the call to the API from my Angular controller.
At the moment my code looks like so:
savvyShop.controller('ProductsCtrl', function($scope) {
$scope.apiResult = $http.get('https://api.semantics3.com/v1/products?q={"cat_id":13658,"brand":"Toshiba","model":"Satellite"}')
});
Unfortunately, there would be no way you can do this from the client-side (via AJAX). This is because you're trying to make a cross-domain request, which all Javascript engines do not allow. In general, if the API provides a JSONP endpoint, you could use that to make cross-domain requests. However, Semantics3 does not have one.
You could write a server-side script that effectively acts as a proxy between the client and our Semantics3 servers. It would basically pass on whatever queries you send to our URL, receive the results, and send it to the client. That way, you can use $http.get in AngularJS to run those queries.

RESTful API - Custom Application - C#, Java, php?

This is really basic.I want to implement a RESTful web API.
Now I know you can write custom applications and scripts to integrate with the API.
What I need to know:
In what languages can you write this API? C#, Java, php?
When building/programming a program that implements this API, is this the client and the software that issued the API the server? (eg. Dropbox would be the server and the custom app that integrates with the Dropbox API is the Client?
Thank you.
A REST API can be built in any programming language that allows you to handle HTTP requests (or can be attached to a Web server as a handler for requests). The two methods I've been using:
Stand-alone Windows service implementing a REST service using WCF
WEB server Apache + PHP
You are correct about the terminology. A program consuming a service is called the client, a program providing a service is called the server (while actually in the PHP approach, Apache would be the server as it is taking the request and having the script handle it).
Additional nitpicking: JQuery is not a language, but a framework to help you use some JavaScript features more easily.
On your comment Recap:
Close :-) The Client transfers JSON/XML/whatever to a server using HTTP requests. The Client can be written in any language that can perform HTTP requests.
On the server side, there needs to be some application that handles the HTTP requests (service), also written in any language, as long as it "speaks" HTTP.
The API is the definition of which operations are possible, for example, adding user accounts, getting the current time, etc. (this is what you define - what do you want your service to do?).
The JSON/XML/whatever that you transfer is the workload, the parameters for the API call. For example, if you want to add a new user to your system, the workload could be the new user name, the real name, the eMail address and some other details about the user. If the API call returns the current server time, you might not need any parameters at all, but you get back JSON/XML/whatever from the service.
The actual call being made is determined by the URL you call. For example, the URL for adding a user could be http://localhost/myrestservice/adduser and you'd perform a POST request against that URL with the required workload. For the time example, the URL could be http://localhost/myrestservice/getservertime and you'd perform a GET request against that URL.
I suggest that you read about how REST services actually work before you start, as I see some question marks on your face ;-)
Short:
API = available operations (=> URLs)
Parameters to API calls = JSON/XML/Plain Text/whatever
Client = calls the service through HTTP
Service = handles the calls, replies to client in response to HTTP requests
If you are a php programmer and familiar with Codeigniter framework then go here : Working with RESTful Services in CodeIgniter.
visit also : Rest Tutorial
First of all, you should begin with learning what is a RESTful API.
http://en.wikipedia.org/wiki/Representational_state_transfer
http://www.restapitutorial.com/
http://rest.elkstein.org/
In what languages can you write this API? C#, Java, php, jQuery?
You can write an API in any language. What can help is the framework you'd be using. JQuery is not a language, but a framework for integrating Javascript application in every web browser, so it won't help.
I'd advice you to use a microframework to write your first RESTful API, because they usually are easy to use and help focus on the important (bottle/flask in python, express in javascript, silex in php, spark in java or nina in C#)
When building/programming a program that implements this API, is this the client and the software that issued the API the server? (eg. Dropbox would be the server and the custom app that integrates with the Dropbox API is the Client?
You're right, the server is providing you the service, hence the API. The client is user to that API, and implementing it into something useful.
As most of the people stated already, you can do this in just about any language.
Might I suggest that you look into NodeJS? If so, check out Restify: http://mcavage.github.io/node-restify/
There's a nice community behind NodeJS and I think it's quite open to newcomers. Just try not to pick up bad habits from JavaScript pitfalls. If you're new to programming, I'd suggest reading some intro book.
good luck!

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.