SlideShare a Scribd company logo
1 of 22
APIs Dynamic Service Mocks andTests with NodeJS
Newman & Express modules
Prepared and Presented by Harish Anand Thiru Kumareshan,
for Clivarsity Demo Session
on 1st March 2019
Topics Covered
Introduction To API/Service Mocking,
– What is an API, how to define? And Introduction to Swagger
– What is API Mocking? and What advantages can it give?
Mocking APIs
– How to Mock APIs,
– Any Ready-made tools?
– What advantages and disadvantages Ready-made tools do have?
Dynamic API Mocks with NodeJs Express Module
– Why to go For Custom API Stubs,
– Introduction to NodeJs, advantages/disadvantages of the npm modules
– Creating a Sample Mock with the custom API framework
Developing Automated Testsuite with Mocks before actual API
– Introduction and How to On Postman CLI
– Adding newman to Dynamic Mock project
– Scheduling with Cron Jobs and Defining Reporting styles and Channel
Deploying “Service Mocks with Automated Tests Package” & CI
– Versioning with Git
– Dockizing the Node Package,
– Introduction to Google App Engine (GAE), Google Kubernetes Engine (GKE), Google Cloud Build (GCB)
– Introduction and Sample CI pipelines
What is an API?
A simple Google search can get you the following-
“a set of functions and procedures allowing the creation of applications that access the
features or data of an operating system, application, or other service.”
But what does that mean!!
Introduction To API/Service Mocking
For understanding the same, first we see what a physical interface is, again from google ;-)
– a point where two systems, subjects, organizations, etc. meet and interact.
– a device or program enabling a user to communicate with a computer.
Introduction To API/Service Mocking
Why and How to define an API
As we just got from the previous image, each internal component inside a laptop is exposed
with an unique/shared Interface, so is not required for a company which makes the laptop to
dump all hardware in one unit, instead it can build the core which shares the port for the users
to add their necessary hardware to it.
Eg., Laptops doesn’t restrict user from using only its inbuilt monitor but can allow user to add
any compatible display device by exposing it display port.
This port exposing creates an ecosystem, where the usability and quality of the laptop/device
can be improved with future inventions!
But there is a catch too!! As specifies though laptops expose a display port, but it
won’t accept any display device, it can detect and work only with the compatible/predefined
display devices.
Introduction To API/Service Mocking
And why there is this compatibility issue and why can’t the display port accepts any display
device?
The answer may simple but is also vague as is dependents on many factor ranging from –
Security to Performance.
And also to design a peripheral for another device, one need to know how the signals are to
be transferred, and to which internal cores the signals to be sent, basically they need to know
the complete architecture/operations of the actual device (laptop) to develop its peripheral
device(External LCD Monitor).
To overcome these kinds of issues and to keep the ecosystem go smooth the standards were
introduced. By considering the same display port example, the standards we have like VGA,
DVI, miniDVI, HDMI, Thunderbolt, etc., So anyone can design/manufacture the display device
for the laptop without needing to know the laptop’s internal architecture or how it works, as
long as they stick to the laptop’s display port standards.
Introduction To API/Service Mocking
Same way for an application to expose its api, it need to convey its consuming application
what it needs, to share what it can.
Introduction To API/Service Mocking
And again the next issue, the compatibility (what data need to be sent it and in what format) for
accessing the application to get a desired output is major problem (though recent services has an
option to get the discovery service is again tough to access the discovery service without a known
definition) eg., one application may accept rest call with Input as XML, JSON or form objects, etc., or it
may accepts in rpc calls, etc.,
So this makes tough for anyone to develop an application that consume the api, and again like
hardware one can’t have a general standards implied on the Specific software (This shouldn’t
confused with standards like REST/RPC/SOAP, etc.,).
To avoid these kind of issues, is always a good practice to define the APIs and what it can do,
So anyone can develop any consuming application and need not to worry on how data is been
prepared or how is responded back, as long as he knows the API definition which states what needs to
inputted and in what format to application and what he can get back for the input.
Introduction To API/Service Mocking
Introduction to Swagger
There are many ways to define an API, including a word document, WSDLs, etc.,
One of such tools for defining REST interface are Swagger and OAS, these has a set of
standards to define the API elements, for eg., the API should basically have Request path,
header content, body content, Response code and a Response content.
Swagger and/or OAS has the set of standard rules in creating/forming those API elements, so
to maintain the compatibility throughout the software lifecycle.
Eg., swagger api definition yaml file.
Reference
https://github.com/swagger-api,
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
Introduction To API/Service Mocking
What is API Mocking? and What advantages can it give?
As we now know what is an API, now we can see what API Mocking is? And why we need to mock an API?
Service Mocking is quite called with different names like, stubbing, Service Virtualisation, etc., but all point
to one thing, and for understanding the same we refer the same diagram again, but in a different
perspective,
Here, we can see there are two APIs which are talking to each other, and also with its own Front ends. Now
lets say the API1 is connected to car and which collects all drive stats from the car, and API2 which get the
GPS and acceleration data from the car via API1.
Now, for the API2 has to design/developed/work it expects/needs API1 in place and constant data from the
same, and it will fail to work if no data received from the API1
Introduction To API/Service Mocking
From this scenario, we can clearly see the dependencies among the systems.
Though the API1 is already defined, the API2 can start its development phase.
But for the regression testing on the API2s each release require its dependent API to be up
and running and also makes easy for the debugging the application in development phase
without making the real calls
Advantages:
Ease of Parallel development,
Easy to debug the developing application, without making real calls to the connecting systems,
Independent Regression Tests/ API Releases, enabling CICD,
End to Performance test and effort estimation only on the API been developed, etc.,
Introduction To API/Service Mocking
Mocking/Stubbing APIs- how to and When to?
Mocking/Stubbing APIs, as name suggest we will be sending a dummy values for the data in the
response, for example considering the previous API which receives the GPS and acceleration data
from the car, we know what values are expected from the car but we don’t know what exact values
that we will get in a given time. For this scenario we can simply create a dummy API which can
send a random value for GPS and Acceleration at any given time (in same data format as in the API
definition ie., if the GPS co-ordinates are expected to be in a float then the values be like 40.730862
is generated randomly) like below,
{GPS:
{co_ordinates:
{
Latitude: 40.730862,
Longitude: -73.987156
}
},
Acceleration:
{x:123, y:2244, z=-12323}
}
And for when to Mock? – there are no any hard rules on the same but usually is prescribed to
create the stubs are created before/during the development phase which will help in both
development and regression tests activities and also based on the needs the same is extended and
upgraded on the later regressions
Mocking APIs
Are there any tools readily available for API Mocks?
Answer is yes! There are lots and lots of tools available both Paid and Open Source
Few popular API Mock engines/software/frameworks are,
Mocking APIs
There are lot of pros in using the readily available Mocking frameworks, quite few notable are,
1. Straight solution, simple mapping,
2. Simple and pre-defined standards,
3. Readily available library for different response formats,
4. Can be quick to market,
Though is having great pros, there are few pain points in using the ready solutions like,
1. Will not be having full/native support for all type of calls eg., calls like RPC/DB Mocks
2. Will not be easily/straight solution to be deployable as standalones (mostly open-sourced tools),
3. Though deployable, size of the deploying application is huge as need to compile and build the whole
mocking tool,
4. Mostly static or Limited/No Customizability,
5. Need to stick to the Tool limitations/Standards (Like defining predefined response in files), etc.,
Mocking APIs
Why to go for Custom build API Stubs?
Yes, from the previous slide we could notice that, though the ready made tools provides lots and
lots of features and looks efficient, but its pain points make them as an inefficient solution for long
runs, specially the customizability and deployablity affects its long-run usage.
And though few readily available frameworks like Wiremock are addressing those issues, still
those has issues like defining static responses/JSON files for each response, and though those
frameworks can be altered to support the full flexibility but the effort for the same will again look
like a separate development task.
Hence the need for custom build API stubs, which should address the issues of the readily
available tools and also should carry their benefits.
The custom build APIs can follow any environment/framework/language as far as it can serve the
needs,
Dynamic API Mocks with NodeJs Express Module
The custom build APIs can follow any environment/framework/language as far as it can serve the
needs likes,
1. Should be easily customizable,
2. Easy to adapt/anyone can contribute and collaborate,
3. Easy to update/maintain for new CRs
4. Should be easily deployable as standalones,
5. Should support Integrations/can provide/expose API for E2E test simulations,
6. Should be robust and reliable,
7. Should not have any tool dependency (Pointing operation dependency, Not the build dependency
;-)).
Dynamic API Mocks with NodeJs Express Module
Introduction to NodeJs, advantages/disadvantages of the npm modules
This presentation we prefer to explain the custom API mock building with npm modules NodeJs in
framework/environment.
Why NodeJs?
- Open ecosystem easy to contribute and Rich ecosystem, lots of collaborators/Contributors (though declining
recent years) even big companies like Netflix, Paypal, etc.,
- supports for native Java, JavaScript, Groovy,
- Can easily migrate to GO
- Easy to create package/dockerize and can deploy in most servers including clouds
Disadvantages:
-Reliability- Though npm applies strict security and audit on the packages, there case from past where modules
went missing crashes all packages
Dynamic API Mocks with NodeJs Express Module
Creating a Sample Mock with the custom API framework
In this section, we will see how to create a npm package, and how to add the npm modules like
Npm Express, requests etc., to create a basic server, which will respond back the defined
response from a selected element in a available responses JSON object.
Dynamic API Mocks with NodeJs Express Module
In this section, we will see how to create a test collection from Postman, and how to integrate it to
a node package using “neman” module, and also we will see how we select different styles of
reporting including CLI, JSON, Junit, HTML and custom reports.
We will also see dockerize the package and how to have scheduled test runs with cron Jobs
running inside the docker.
Developing Automated Testsuite with Mocks before actual API
In this section, we will see how to have version control on the test package using GIT/SVN. We
will explore few cloud operations and terminologies for how to deploy the test solution in a Cloud
server like Google Cloud platform and will see how to create a docker image for test package and
how to call/add the image the cloud build steps in CI verification phase.
Deploying “Service Mocks with Automated Tests Package” & CI
Service virtualization with npm modules updated
Service virtualization with npm modules updated

More Related Content

What's hot

Rhapsody Eclipse
Rhapsody EclipseRhapsody Eclipse
Rhapsody Eclipse
Bill Duncan
 

What's hot (16)

Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
 
Codename one
Codename oneCodename one
Codename one
 
Golden Rules of API Design
Golden Rules of API DesignGolden Rules of API Design
Golden Rules of API Design
 
Performance Testing REST APIs
Performance Testing REST APIsPerformance Testing REST APIs
Performance Testing REST APIs
 
Eclipse and API tooling
Eclipse and API toolingEclipse and API tooling
Eclipse and API tooling
 
Web API Design: Crafting Interfaces that Developers Love
Web API Design:  Crafting Interfaces that Developers LoveWeb API Design:  Crafting Interfaces that Developers Love
Web API Design: Crafting Interfaces that Developers Love
 
IO State In Distributed API Architecture
IO State In Distributed API ArchitectureIO State In Distributed API Architecture
IO State In Distributed API Architecture
 
Introduction to java advanced imaging
Introduction to java advanced imagingIntroduction to java advanced imaging
Introduction to java advanced imaging
 
Introduction to java advanced imaging
Introduction to java advanced imagingIntroduction to java advanced imaging
Introduction to java advanced imaging
 
Api Abstraction & Api Chaining
Api Abstraction & Api ChainingApi Abstraction & Api Chaining
Api Abstraction & Api Chaining
 
Moving into API documentation writing
Moving into API documentation writingMoving into API documentation writing
Moving into API documentation writing
 
Resume
ResumeResume
Resume
 
Xamarin in real life: our MVP approach - Daniele Leombruni Antonino Cacace - ...
Xamarin in real life: our MVP approach - Daniele Leombruni Antonino Cacace - ...Xamarin in real life: our MVP approach - Daniele Leombruni Antonino Cacace - ...
Xamarin in real life: our MVP approach - Daniele Leombruni Antonino Cacace - ...
 
Rhapsody Eclipse
Rhapsody EclipseRhapsody Eclipse
Rhapsody Eclipse
 
All you need to know about latest php version 7.4
All you need to know about latest php version 7.4All you need to know about latest php version 7.4
All you need to know about latest php version 7.4
 
Apiworld
ApiworldApiworld
Apiworld
 

Similar to Service virtualization with npm modules updated

Similar to Service virtualization with npm modules updated (20)

Why You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API DevelopmentWhy You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API Development
 
Top 11 API testing tools for 2022
Top 11 API testing tools for 2022Top 11 API testing tools for 2022
Top 11 API testing tools for 2022
 
Case study for software architect
Case study for software architectCase study for software architect
Case study for software architect
 
RefCard API Architecture Strategy
RefCard API Architecture StrategyRefCard API Architecture Strategy
RefCard API Architecture Strategy
 
Frequently asked MuleSoft Interview Questions and Answers from Techlightning
Frequently asked MuleSoft Interview Questions and Answers from TechlightningFrequently asked MuleSoft Interview Questions and Answers from Techlightning
Frequently asked MuleSoft Interview Questions and Answers from Techlightning
 
Designing Good API & Its Importance
Designing Good API & Its ImportanceDesigning Good API & Its Importance
Designing Good API & Its Importance
 
Api tools overview
Api tools overviewApi tools overview
Api tools overview
 
Api design part 1
Api design part 1Api design part 1
Api design part 1
 
JOSA TechTalks - RESTful API Concepts and Best Practices
JOSA TechTalks - RESTful API Concepts and Best PracticesJOSA TechTalks - RESTful API Concepts and Best Practices
JOSA TechTalks - RESTful API Concepts and Best Practices
 
Microservices&ap imanagement
Microservices&ap imanagementMicroservices&ap imanagement
Microservices&ap imanagement
 
Top 11 api testing tools for 2022
Top 11 api testing tools for 2022Top 11 api testing tools for 2022
Top 11 api testing tools for 2022
 
Practical guide to building public APIs
Practical guide to building public APIsPractical guide to building public APIs
Practical guide to building public APIs
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
Spring boot
Spring bootSpring boot
Spring boot
 
Building APIs using Laravel - A simple approach to scale
Building APIs using Laravel - A simple approach to scaleBuilding APIs using Laravel - A simple approach to scale
Building APIs using Laravel - A simple approach to scale
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
 
Review Paper on Online Java Compiler
Review Paper on Online Java CompilerReview Paper on Online Java Compiler
Review Paper on Online Java Compiler
 
Spring boot vs spring framework razor sharp web applications
Spring boot vs spring framework razor sharp web applicationsSpring boot vs spring framework razor sharp web applications
Spring boot vs spring framework razor sharp web applications
 
Api Testing.pdf
Api Testing.pdfApi Testing.pdf
Api Testing.pdf
 
Api clarity webinar
Api clarity webinarApi clarity webinar
Api clarity webinar
 

Recently uploaded

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 

Recently uploaded (20)

What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
 
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityAPVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 

Service virtualization with npm modules updated

  • 1. APIs Dynamic Service Mocks andTests with NodeJS Newman & Express modules Prepared and Presented by Harish Anand Thiru Kumareshan, for Clivarsity Demo Session on 1st March 2019
  • 2. Topics Covered Introduction To API/Service Mocking, – What is an API, how to define? And Introduction to Swagger – What is API Mocking? and What advantages can it give? Mocking APIs – How to Mock APIs, – Any Ready-made tools? – What advantages and disadvantages Ready-made tools do have? Dynamic API Mocks with NodeJs Express Module – Why to go For Custom API Stubs, – Introduction to NodeJs, advantages/disadvantages of the npm modules – Creating a Sample Mock with the custom API framework Developing Automated Testsuite with Mocks before actual API – Introduction and How to On Postman CLI – Adding newman to Dynamic Mock project – Scheduling with Cron Jobs and Defining Reporting styles and Channel Deploying “Service Mocks with Automated Tests Package” & CI – Versioning with Git – Dockizing the Node Package, – Introduction to Google App Engine (GAE), Google Kubernetes Engine (GKE), Google Cloud Build (GCB) – Introduction and Sample CI pipelines
  • 3. What is an API? A simple Google search can get you the following- “a set of functions and procedures allowing the creation of applications that access the features or data of an operating system, application, or other service.” But what does that mean!! Introduction To API/Service Mocking
  • 4. For understanding the same, first we see what a physical interface is, again from google ;-) – a point where two systems, subjects, organizations, etc. meet and interact. – a device or program enabling a user to communicate with a computer. Introduction To API/Service Mocking
  • 5. Why and How to define an API As we just got from the previous image, each internal component inside a laptop is exposed with an unique/shared Interface, so is not required for a company which makes the laptop to dump all hardware in one unit, instead it can build the core which shares the port for the users to add their necessary hardware to it. Eg., Laptops doesn’t restrict user from using only its inbuilt monitor but can allow user to add any compatible display device by exposing it display port. This port exposing creates an ecosystem, where the usability and quality of the laptop/device can be improved with future inventions! But there is a catch too!! As specifies though laptops expose a display port, but it won’t accept any display device, it can detect and work only with the compatible/predefined display devices. Introduction To API/Service Mocking
  • 6. And why there is this compatibility issue and why can’t the display port accepts any display device? The answer may simple but is also vague as is dependents on many factor ranging from – Security to Performance. And also to design a peripheral for another device, one need to know how the signals are to be transferred, and to which internal cores the signals to be sent, basically they need to know the complete architecture/operations of the actual device (laptop) to develop its peripheral device(External LCD Monitor). To overcome these kinds of issues and to keep the ecosystem go smooth the standards were introduced. By considering the same display port example, the standards we have like VGA, DVI, miniDVI, HDMI, Thunderbolt, etc., So anyone can design/manufacture the display device for the laptop without needing to know the laptop’s internal architecture or how it works, as long as they stick to the laptop’s display port standards. Introduction To API/Service Mocking
  • 7. Same way for an application to expose its api, it need to convey its consuming application what it needs, to share what it can. Introduction To API/Service Mocking
  • 8. And again the next issue, the compatibility (what data need to be sent it and in what format) for accessing the application to get a desired output is major problem (though recent services has an option to get the discovery service is again tough to access the discovery service without a known definition) eg., one application may accept rest call with Input as XML, JSON or form objects, etc., or it may accepts in rpc calls, etc., So this makes tough for anyone to develop an application that consume the api, and again like hardware one can’t have a general standards implied on the Specific software (This shouldn’t confused with standards like REST/RPC/SOAP, etc.,). To avoid these kind of issues, is always a good practice to define the APIs and what it can do, So anyone can develop any consuming application and need not to worry on how data is been prepared or how is responded back, as long as he knows the API definition which states what needs to inputted and in what format to application and what he can get back for the input. Introduction To API/Service Mocking
  • 9. Introduction to Swagger There are many ways to define an API, including a word document, WSDLs, etc., One of such tools for defining REST interface are Swagger and OAS, these has a set of standards to define the API elements, for eg., the API should basically have Request path, header content, body content, Response code and a Response content. Swagger and/or OAS has the set of standard rules in creating/forming those API elements, so to maintain the compatibility throughout the software lifecycle. Eg., swagger api definition yaml file. Reference https://github.com/swagger-api, https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md Introduction To API/Service Mocking
  • 10. What is API Mocking? and What advantages can it give? As we now know what is an API, now we can see what API Mocking is? And why we need to mock an API? Service Mocking is quite called with different names like, stubbing, Service Virtualisation, etc., but all point to one thing, and for understanding the same we refer the same diagram again, but in a different perspective, Here, we can see there are two APIs which are talking to each other, and also with its own Front ends. Now lets say the API1 is connected to car and which collects all drive stats from the car, and API2 which get the GPS and acceleration data from the car via API1. Now, for the API2 has to design/developed/work it expects/needs API1 in place and constant data from the same, and it will fail to work if no data received from the API1 Introduction To API/Service Mocking
  • 11. From this scenario, we can clearly see the dependencies among the systems. Though the API1 is already defined, the API2 can start its development phase. But for the regression testing on the API2s each release require its dependent API to be up and running and also makes easy for the debugging the application in development phase without making the real calls Advantages: Ease of Parallel development, Easy to debug the developing application, without making real calls to the connecting systems, Independent Regression Tests/ API Releases, enabling CICD, End to Performance test and effort estimation only on the API been developed, etc., Introduction To API/Service Mocking
  • 12. Mocking/Stubbing APIs- how to and When to? Mocking/Stubbing APIs, as name suggest we will be sending a dummy values for the data in the response, for example considering the previous API which receives the GPS and acceleration data from the car, we know what values are expected from the car but we don’t know what exact values that we will get in a given time. For this scenario we can simply create a dummy API which can send a random value for GPS and Acceleration at any given time (in same data format as in the API definition ie., if the GPS co-ordinates are expected to be in a float then the values be like 40.730862 is generated randomly) like below, {GPS: {co_ordinates: { Latitude: 40.730862, Longitude: -73.987156 } }, Acceleration: {x:123, y:2244, z=-12323} } And for when to Mock? – there are no any hard rules on the same but usually is prescribed to create the stubs are created before/during the development phase which will help in both development and regression tests activities and also based on the needs the same is extended and upgraded on the later regressions Mocking APIs
  • 13. Are there any tools readily available for API Mocks? Answer is yes! There are lots and lots of tools available both Paid and Open Source Few popular API Mock engines/software/frameworks are, Mocking APIs
  • 14. There are lot of pros in using the readily available Mocking frameworks, quite few notable are, 1. Straight solution, simple mapping, 2. Simple and pre-defined standards, 3. Readily available library for different response formats, 4. Can be quick to market, Though is having great pros, there are few pain points in using the ready solutions like, 1. Will not be having full/native support for all type of calls eg., calls like RPC/DB Mocks 2. Will not be easily/straight solution to be deployable as standalones (mostly open-sourced tools), 3. Though deployable, size of the deploying application is huge as need to compile and build the whole mocking tool, 4. Mostly static or Limited/No Customizability, 5. Need to stick to the Tool limitations/Standards (Like defining predefined response in files), etc., Mocking APIs
  • 15. Why to go for Custom build API Stubs? Yes, from the previous slide we could notice that, though the ready made tools provides lots and lots of features and looks efficient, but its pain points make them as an inefficient solution for long runs, specially the customizability and deployablity affects its long-run usage. And though few readily available frameworks like Wiremock are addressing those issues, still those has issues like defining static responses/JSON files for each response, and though those frameworks can be altered to support the full flexibility but the effort for the same will again look like a separate development task. Hence the need for custom build API stubs, which should address the issues of the readily available tools and also should carry their benefits. The custom build APIs can follow any environment/framework/language as far as it can serve the needs, Dynamic API Mocks with NodeJs Express Module
  • 16. The custom build APIs can follow any environment/framework/language as far as it can serve the needs likes, 1. Should be easily customizable, 2. Easy to adapt/anyone can contribute and collaborate, 3. Easy to update/maintain for new CRs 4. Should be easily deployable as standalones, 5. Should support Integrations/can provide/expose API for E2E test simulations, 6. Should be robust and reliable, 7. Should not have any tool dependency (Pointing operation dependency, Not the build dependency ;-)). Dynamic API Mocks with NodeJs Express Module
  • 17. Introduction to NodeJs, advantages/disadvantages of the npm modules This presentation we prefer to explain the custom API mock building with npm modules NodeJs in framework/environment. Why NodeJs? - Open ecosystem easy to contribute and Rich ecosystem, lots of collaborators/Contributors (though declining recent years) even big companies like Netflix, Paypal, etc., - supports for native Java, JavaScript, Groovy, - Can easily migrate to GO - Easy to create package/dockerize and can deploy in most servers including clouds Disadvantages: -Reliability- Though npm applies strict security and audit on the packages, there case from past where modules went missing crashes all packages Dynamic API Mocks with NodeJs Express Module
  • 18. Creating a Sample Mock with the custom API framework In this section, we will see how to create a npm package, and how to add the npm modules like Npm Express, requests etc., to create a basic server, which will respond back the defined response from a selected element in a available responses JSON object. Dynamic API Mocks with NodeJs Express Module
  • 19. In this section, we will see how to create a test collection from Postman, and how to integrate it to a node package using “neman” module, and also we will see how we select different styles of reporting including CLI, JSON, Junit, HTML and custom reports. We will also see dockerize the package and how to have scheduled test runs with cron Jobs running inside the docker. Developing Automated Testsuite with Mocks before actual API
  • 20. In this section, we will see how to have version control on the test package using GIT/SVN. We will explore few cloud operations and terminologies for how to deploy the test solution in a Cloud server like Google Cloud platform and will see how to create a docker image for test package and how to call/add the image the cloud build steps in CI verification phase. Deploying “Service Mocks with Automated Tests Package” & CI