An open API service indexing awesome lists of open source software.

https://github.com/vixalien/feathers_oak

Feathers Oak framework bindings and REST provider
https://github.com/vixalien/feathers_oak

deno feathers oak

Last synced: 23 days ago
JSON representation

Feathers Oak framework bindings and REST provider

Awesome Lists containing this project

README

        

# feathers_oak

[Feathers](https://feathersjs.com) - [Oak](https://github.com/oakserver/oak) 🦕
framework bindings and REST provider. Oak works under both Deno and NPM.

## Usage

`feathers_oak` requires 2 pre-existing `feathers` and `oak` apps. It just binds
them together so that you can use your services from oak as a REST endpoint with
oak.

```ts

// Oak
import { Application } from "https://deno.land/x/oak/mod.ts";

// Importing feathers
import { feathers } from "https://deno.land/x/feathers/mod.ts";
import {
errorHandler,
restRouter,
routing,
} from "https://deno.land/x/feathers_oak/mod.ts";

// we will use mongo and it's feathers adapter as an example, but you can use whatever database adapter you like
import { MongoClient, ObjectId } from "https://deno.land/x/mongo/mod.ts";
import { MongoService } from "https://deno.land/x/feathers_mongo/mod.ts";

// --- Services ---

// initialising the mongo client & service
const client = new MongoClient();
await client.connect("mongodb://127.0.0.1:27017");
const db = client.database("test");

interface UserSchema {
_id: ObjectId;
username: string;
password: string;
age: number;
}

const users = db.collection("users");
const Users = new MongoService({
// set the collection
Model: users,
// default pagination options
paginate: {
default: 10,
max: 50,
},
});

// --- Feathers ---

// creating the feathers app
const app = feathers();
// IMPORTANT: must initialize routing before adding services
app.configure(routing() as any);
app.use("users", Users);

// --- Oak ---

// creating the oak site & adding feathers REST router
const site = new Application();
const router = restRouter(app);
site.use(errorHandler());
site.use(router.routes(), router.allowedMethods());

// start the site
site.listen({
post: 3000,
});
```

NOTE: this project is WIP, and some things may not work or misbehave. This
README will be updated when this package reachs `v1`.