How to create Mock REST API services through mocky.io | Mock REST API's for Testing

Опубликовано: 29 Октябрь 2024
на канале: Tech Forum
6,781
29

#Mocky #mockrestapi #mockservices

Mocky is a simple service that allows generating custom HTTP responses. It's helpful when you want to mock the back end service responses for those the development is in progress.

Don't wait for the back end to be ready, generate custom API responses with Mocky and start working on your application straight away

It is a free and unlimited online service, Mocky is compatible with JS, Mobile, and Server applications, featuring CORS, JSONP, and GZIP responses. No authentication, you can directly call it!

It is an open-source, distributed with Apache 2 license on Github - @lafont/Mocky

The mock services can be built quickly through online - @

mocky.io enables the JSONP support by Adding ?callback=myfunction to your Mocky URL to transform the response into a JSONP response.

The CORS Preflight requests are automatically accepted from any origin.

Add the ?mocky-delay=100ms parameter to your Mocky URL to delay the response. Maximum delay: 60s.

You're allowed to call your Mocky up to 100 times per second. Call it at least once in the year to postpone automatic deletion.

You can also quickly set up the mocky.io into your local machine

Clone the Mocky GitHub repository to your localhost- @lafont/Mocky
As a prerequisite ensure node.js and yarn installed into your system

Install the react-scripts and typescript through the following commands
npm install react-scripts --save
yarn add typescript

Install Scala SBT - @d.html

Install postgresql database - @ds/postgres-postgresql-downloads

Create a database with the name mocky and execute the below SQLs to create the user and to enable the required permissions

CREATE ROLE mocky LOGIN PASSWORD 'mocky' NOINHERIT CREATEDB;

ALTER USER mocky WITH SUPERUSER;

Start the client application
set REACT_APP_API_URL=@ (backend API URL)
cd c:\Mocky\client
execute yarn start:dev

Now the front end is accessible through the following URL - @

Start the server

set MOCKY_ADMIN_PASSWORD=Password123!
set MOCKY_ENVIRONMENT=dev
set MOCKY_ENDPOINT=@
set MOCKY_CORS_DOMAIN=@

cd c:\Mocky\server
execute sbt run

Now you should be able to manage the mock API's