Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
onechiporenko committed Jan 29, 2018
1 parent 7adc795 commit f7d61b4
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ npm i swarm-host --save

```typescript
import compression = require('compression');
import {Server} from 'swarm-host/dist';
import {Server} from 'swarm-host';

// server itself
const server = Server.getServer();
Expand All @@ -39,7 +39,7 @@ Server without any routes is useless. It's time to add them.
Every Route is an instance of the class `Route`. It may be created by calling static method `createRoute`:

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.createRoute('get', '/all-users', (req, res, next, lair) => {
// ...
});
Expand Down Expand Up @@ -69,7 +69,7 @@ res.status(404).json({});
Route may be added to server by calling `addRoute`:

```typescript
import {Server, Route} from 'swarm-host/dist';
import {Server, Route} from 'swarm-host';
const server = Server.getServer();
server.addRoute(Route.createRoute(/*...*/));
```
Expand All @@ -79,7 +79,7 @@ server.addRoute(Route.createRoute(/*...*/));
[Lair-db](https://github.com/onechiporenko/lair) is used like a data-storage in the Swarm-host. It has two methods to work with Lair-db. First one is a `addFactory`. It does the same as a `lair.registerFactory` and takes two parameters - factory-instance and factory-name:

```typescript
import {Server, Factory} from 'swarm-host/dist';
import {Server, Factory} from 'swarm-host';

const server = Server.getServer();
server.addFactory(Factory.create({/* ... */}), 'factory-name');
Expand All @@ -88,7 +88,7 @@ server.addFactory(Factory.create({/* ... */}), 'factory-name');
Second method is a `createRecords`. It's just a wrapper for `lair.createRecords`. It takes two parameters - factory name and records count to create:

```typescript
import {Server, Factory} from 'swarm-host/dist';
import {Server, Factory} from 'swarm-host';

const server = Server.getServer();
server.createRecords('factory-name', 10);
Expand All @@ -107,14 +107,14 @@ Predefined route `get` is used to get one record or all records of the given typ
**Multiple records:**

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.get('/all-users', 'user', {depth: 1, ignoreRelated: ['subject']});
```

It's equal to:

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.createRoute('get', '/all-users', (req, res, next, lair) => {
const data = lair.getAll('user', {
depth: 1,
Expand All @@ -127,14 +127,14 @@ Route.createRoute('get', '/all-users', (req, res, next, lair) => {
**Single record:**

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.get('/all-users/:id', 'user', {depth: 1, ignoreRelated: ['subject']});
```

It's equal to:

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.createRoute('get', '/all-users', (req, res, next, lair) => {
const data = lair.getOne('user', req.params.id, {
depth: 1,
Expand All @@ -151,14 +151,14 @@ _Only routes with a single dynamic part are supported for `Route.get` used to ge
Predefined route `post` is used to create a record of the given type.

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.post('/all-users', 'user', {depth: 1});
```

It's equal to:

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.createRoute('post', '/all-users', (req, res, next, lair) => {
const data = lair.createOne('user', req.body, {depth: 1});
res.json(data);
Expand All @@ -170,14 +170,14 @@ Route.createRoute('post', '/all-users', (req, res, next, lair) => {
Both predefined routes can be used to update a record of the given type by its `id`.

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.patch('/all-users/:id', 'user', {depth: 1});
```

It's equal to:

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.createRoute('patch', '/all-users/:id', (req, res, next, lair) => {
const data = lair.updateOne('user', req.params.id, req.body, {depth: 1});
res.json(data);
Expand All @@ -189,14 +189,14 @@ Route.createRoute('patch', '/all-users/:id', (req, res, next, lair) => {
Predefined route `delete` is used to delete a single record of the given type by its `id`.

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.delete('/all-users', 'user');
```

It's equal to:

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.createRoute('delete', '/all-users/:id', (req, res, next, lair) => {
lair.deleteOne('user', req.params.id);
res.json({});
Expand Down Expand Up @@ -224,12 +224,12 @@ function handler(req, res, data, lair) {
Both Routes bellow are doing the same:

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.get('/all-users', 'user', {depth: 1});
```

```typescript
import {Route} from 'swarm-host/dist';
import {Route} from 'swarm-host';
Route.get('/all-users', 'user', {depth: 1}, (req, res, data, lair) => {
res.json(data);
});
Expand All @@ -240,7 +240,7 @@ Such extra-handlers are useful to serialize data before sending them in the Resp
### Complex example

```typescript
import {Server, Factory, Route} from 'swarm-host/dist';
import {Server, Factory, Route} from 'swarm-host';
const faker = require('faker'); // npm i faker --save
const server = Server.getServer();
server.namespace = '/api/v1';
Expand Down

0 comments on commit f7d61b4

Please sign in to comment.