Skip to content
Mihael Konjević edited this page May 29, 2014 · 3 revisions

APItizer exposes a very simple API. apitizer objects holds following functions and objects:

- `addSchema(name, schema)` - add schema to APItizer
- `getSchema` - get schema from the APItizer
- `dropSchemas` - drop all schemas added to the APItizer
- `validateSchema(name, data)` - validate data based on the schema
- `generateFromSchema(name, overrides)` - generate one object based on the schema. This will not modify any of the existing stores
- `schemaStore(name, count, overrides, api)` - return store based on the schema:
	+ `name` - name of the schema
	+ `count` - how much items to put in the store
	+ `overrides` (optional) - object that allows you to override the generators
	+ `api` (optional) - provide custom API implementation
- `types` - object holding all types and formats used in the schema
- `fixture` - function to create fixtures for data
- `API` - default API implementation

Fixtures

Fixtures can be created in two ways:

apitizer.fixture(url, fnHandler);

This will implement a function that will be called when request is made to the URL. You can also provide a request method in the URL: GET /foo and you can include placeholders for params: DELETE /foo/{id}.

Another way is to register a resource:

apitizer.fixture.resource(baseUrl, store);

For instance, if you called it with:

apitizer.fixture.resource('/users', userStore);

It would create these handlers:

"GET /users" // return users
"GET /users/{id}" // return user based on the id
"POST /users" // create new user
"PUT /users/{id}" // update existing user
"DELETE /users/{id}" // delete existing user from the store
Clone this wiki locally