DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Phantom APIs Are Eating Your Attack Surface, and Most Security Teams Are Still Looking the Other Way
  • How to Set MX Records via API: Automate Email Routing Programmatically
  • I Reverse-Engineered 50 API Breaches. The Same Five Mistakes Keep Appearing.
  • The Documentation Crisis Nobody Sees: Why AI Agents Are Breaking Faster Than Humans Can Document Them

Trending

  • Reducing RAG Hallucinations With Relationship-Aware Retrieval
  • Cutting Data Pipeline Costs and Data Freshness Issues With Netflix Maestro and Apache Iceberg: A Practical Tutorial
  • The Latency Tax That’s Hidden in Cloud-Native Systems (and the Hard Lessons I Learned to Minimize It)
  • The Trust Problem in Modern SaaS: Why Your Authentication Succeeded, and You Still Got Breached
  1. DZone
  2. Data Engineering
  3. Databases
  4. Mock APIs Using sMockin

Mock APIs Using sMockin

This tutorial aims to explain how to improve time when it is required for third-party system integration. Read below to find out how to do this yourself!

By 
Rafael Marques user avatar
Rafael Marques
·
Jan. 10, 22 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
5.4K Views

Join the DZone community and get the full member experience.

Join For Free

Hi Everyone,

The main goal of this article will be to explain how to improve our time when is required to integrate with a third-party system. Usually, it is an API and the developer doesn't have control over it. Moreover, the developer usually needs to mock the API, the sMockin could help the teams with this hard task. 

What Is a Mock API Server?

A mock API imitates a real API server by providing realistic mock API responses to requests. They can be on your local machine or the public Internet. Responses can be static or dynamic, and simulate the data the real API would return, matching the schema with data types, objects, and arrays.

Mocked API.

Mocked API


A Simple Overview About sMockin:

sMockin is an API mocking tool used to dynamically simulate HTTP endpoints.

Featuring a rich UI and HTTP mock server, replicating existing or creating new APIs can be done quickly both with JavaScript or without code.

Whether you are a developer who needs to simulate RESTFul endpoints or an engineer working with complex SOA / IoT / microservice infrastructure, sMockin can help by mimicking any services that are either unavailable or otherwise too difficult or time-consuming to set up.

sMockin runs as a small web app that can be either installed locally onto a personal machine or hosted centrally and used by multiple users, all information over sMockin is here.

Starting and Creating a Mock API

Requirements:

  • Java 8 and Maven

Mocking an API

  • Download the code and run the sMockin.
    • Shell
       
      git clone https://github.com/mgtechsoftware/smockin.git
      
      
  • Run the mvn install
    • Shell
       
      $ cd smockin
      $ mvn clean install


  • Install and Start
    • Shell
       
      $ ./install.sh
      $ ./start.sh


  • Start the Mock Server

    • Open this URL.Mock Server screenshot.

  • Create an HTTP mock:

    • Click on the New HTTP Endpoint button.
    • Create the HTTP mock as you desire.HTTP Mock.

That's it! After you test the mocks API, call the endpoint using curl or other tools, then you'll see the test was done using the hey(hey -n 22 -c 1 -m GET http://localhost:8001/invoices). In the image below, there are 10 requests with status code 200, 10 with status code 400 and 2 with status code 500.

Status codes.

And, we're finally done. I hope this article sheds some light on how to use Smockin to mock API responses for requests. sMockin has other options; it can be used as standalone, binary, source, and docker.

API

Opinions expressed by DZone contributors are their own.

Related

  • Phantom APIs Are Eating Your Attack Surface, and Most Security Teams Are Still Looking the Other Way
  • How to Set MX Records via API: Automate Email Routing Programmatically
  • I Reverse-Engineered 50 API Breaches. The Same Five Mistakes Keep Appearing.
  • The Documentation Crisis Nobody Sees: Why AI Agents Are Breaking Faster Than Humans Can Document Them

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook