Giter Site home page Giter Site logo

aliencube / simple-mock-web-service Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 3.0 41.79 MB

provides RESTful web services, for mocking purpose, to be consumed in any JavaScript frameworks using AJAX call.

Home Page: http://aliencube.github.io/Simple-Mock-Web-Service

License: MIT License

C# 53.36% ApacheConf 17.02% HTML 4.48% CSS 8.50% JavaScript 3.25% ASP 0.16% PowerShell 10.66% Shell 0.05% Pascal 2.52%

simple-mock-web-service's Introduction

Simple Mock Web Service

Simple Mock Web Service (SimpleMock) provides RESTful web services, for mocking purpose, to be consumed in any JavaScript frameworks using AJAX call.

Background

SimpleMock is originally inspired by node EasyMock managed by Patrick Boos, which provides a web server, using node.js, for mocking web services. Instead of using node.js, SimpleMock does its features through ASP.NET Web API.

System Requirements

In order to run SimpleMock, it requires:

NOTE : SimpleMock can be run on IIS 6 with a 3rd party URL rewriting module like Ionics Isapi Rewrite Filter(IIRF), Helicon URL Rewrite or UrlRewritingNet.UrlRewrite, as long as .NET Framework 4.5 or higher is installed and run on the server machine.

Getting Started

Once your IIS has been setup with a URL of simplemock.local, for example, just simply run one of the following URLs:

GET		http://simplemock.local/api/contents
GET		http://simplemock.local/api/content/1

Then you will be able to see the JSON formatted response. Those requests are basically using the GET method. If you are using Fiddler or something like that, you can also run the following requests:

POST	http://simplemock.local/api/content
PUT		http://simplemock.local/api/content/1
DELETE	http://simplemock.local/api/content/1

Then you will be also able to confirm the JSON response within Fiddler.

Configuration

If you want to add your custom RESTful URLs, you can simply modify the SimpleMockWebService.config file.

<?xml version="1.0" encoding="utf-8" ?>
<simpleMockWebService>
  <globalSettings webApiPrefix="api" verbs="GET,POST,PUT,DELETE" jsonFileExtensions="json,js,txt" />
  <apiGroups>
    <apiGroup key="Content">
      <apis>
        <api key="GetContents" group="Content" method="get" url="/api/contents" src="~/responses/get.contents.json" />
        <api key="GetContentById" method="get" url="/api/content/1" src="get.content.1.json" delay="0" />
        <api key="PostContent" method="post" url="/api/content" delay="0" />
        <api key="PutContentById" method="put" url="/api/content/1" src="/responses/put.content.1.json" delay="0" />
        <api key="DeleteContentById" method="delete" url="/api/content/1" src="~/responses/delete.content.1.json" />
      </apis>
    </apiGroup>
  </apiGroups>
</simpleMockWebService>

Global Settings Element

  • webApiPrefix: is the first part of the URL segments after the domain name. Default value is api.
  • verbs: is the list of valid method verbs consumed in this service. Default methods are GET, POST, PUT and DELETE. You can add HEAD or other verbs on your preference.
  • jsonFileExtensions: is the list of valid file extensions storing JSON formatted responses. Default file extensions are json, js, and txt.

API Group Element

  • key: is the unique identifier of the API group element. This key is considered as the second part of the URL segments.

API Element

  • key: is the unique identifier of the API element.
  • group: points to the API group element key, if the second part of the URL segments is different from the key of its parent group element.
  • method: represents the method verb.
  • url: represents the URL.
  • src: points to the physical location where JSON formatted response is situated. Default location of each response file is ~/responses.
  • delay: simulates the server response time in milliseconds.

RESTful Web Services

Each method returns JSON response that is predefined and stored in the specified location on the server.

GET

<api key="GetContents" group="Content" method="get" url="/api/contents" src="~/responses/get.contents.json" />
<api key="GetContentById" method="get" url="/api/content/1" src="get.content.1.json" delay="0" />

The configurations above expect the GET requests below respectively:

http://simplemock.local/api/contents
http://simplemock.local/api/content/1

Therefore, each request returns JSON response respectively like:

[{ "id": 1, "title": "title 1" }, { "id": 2, "title": "title 2" }, { "id": 3, "title": "title 3" }]
{ "id": 1, "title": "title 1" }

POST

<api key="PostContent" method="post" url="/api/content" delay="0" />

The configuration above expects the POST requests below:

http://simplemock.local/api/content

Therefore, the request returns the JSON response like:

{ "id": 1, "title": "title 1" }

PUT

<api key="PutContentById" method="put" url="/api/content/1" src="/responses/put.content.1.json" delay="0" />

The configuration above expects the PUT requests below:

http://simplemock.local/api/content/1

Therefore, the request returns the JSON response like:

{ "id": 1, "title": "title 1" }

DELETE

<api key="DeleteContentById" method="delete" url="/api/content/1" src="~/responses/delete.content.1.json" />

The configuration above expects the DELETE requests below:

http://simplemock.local/api/content/1

Therefore, the request returns the JSON response like:

{ "id": 1, "title": "title 1" }

Other Verbs

Depending on your preferences, you can predefine any acceptable RESTful method and store its desirable response on the server and use it.

License

SimpleMock is released under MIT License.

The MIT License (MIT)

Copyright (c) 2013 aliencube.org

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

simple-mock-web-service's People

Contributors

haruair avatar justinyoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.