Skip to content

Feathers Oak framework bindings and REST provider

Notifications You must be signed in to change notification settings

vixalien/feathers_oak

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

feathers_oak

Feathers - 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.

// 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<UserSchema>("users");
const Users = new MongoService<UserSchema>({
  // 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.

About

Feathers Oak framework bindings and REST provider

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published