Skip to content
A simple server mock
JavaScript CSS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
src
.gitignore
Gruntfile.js
LICENSE
README.md
bower.json
index.html
package.json
srvmock.map
style.css

README.md

srvmock

A simple server mock

It is intended to be used when you don't have a backend communication, so that you can mock all servers responses in order to test the frontend work, validations, callback functions and so on.

The API can be found at the lib folder

###How to use it

You must first define schemas, like this:

	var mySchema = {
		name: 'users',
		fields: [
			{name: 'id', type: 'number', size: 20},
			{name: 'name', type: 'string', size: 20}
		]
	};

And then you must register this schema in order to srvmock to generate content for you:

	srvmock.setSchema(mySchema);

Finally, you can ask srvmock to return a list of data based on that schema:

	/*
	This will give you an array with 12 dinamically generated users
	based on mySchema.

	*/
	var userList = srvmock.httpGet('users', 12);

If you don't pass the second argument, srvmock will only retrieve data from localStorage

How to persist data on localStorage, you ask:

	//this will persist the object containing id = 111 and name = Willian
	//it will also return the id generated by zon API
	srvmock.httpPost('users', {id:111, name: 'Willian'});
You can’t perform that action at this time.