Skip to main content

@phrasecode/odata

Modern OData v4 Server Library for Node.js

npm install @phrasecode/odata

Why Choose @phrasecode/odata?

Build powerful RESTful APIs with standardized querying capabilities

OData v4 Compliant

Full support for OData v4 protocol including $filter, $select,$expand, $orderby, $top, $skip, and $count query options with automatic metadata generation.

🗄️

Sequelize-Powered

Built on Sequelize ORM with support for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, and Oracle. Leverage the power of a mature ORM ecosystem.

🔷

TypeScript Decorators

Define models using intuitive TypeScript decorators. Get full type safety, IntelliSense support, and compile-time validation for your data models.

🚂

Express Integration

Seamless integration with Express.js through ExpressRouter. Set up OData endpoints in minutes with minimal configuration.

Flexible Controllers

Control access with ODataControler allowing you to specify which HTTP methods are permitted (GET) per model.

📋

Auto Metadata

Automatic /$metadata endpoint generation based on your models. Full EDMX support for client tools and OData consumers.

Quick Example

Get started in minutes with a simple, intuitive API

server.ts
import {
Model,
Table,
Column,
DataTypes,
DataSource,
ExpressRouter,
ODataControler,
} from '@phrasecode/odata';
import express from 'express';

// Define a model
@Table({ tableName: 'products' })
class Product extends Model<Product> {
@Column({
dataType: DataTypes.INTEGER,
isPrimaryKey: true,
isAutoIncrement: true,
})
id: number;

@Column({ dataType: DataTypes.STRING })
name: string;

@Column({ dataType: DataTypes.DECIMAL })
price: number;
}

// Create data source
const dataSource = new DataSource({
dialect: 'postgres',
database: 'mydb',
username: 'user',
password: 'password',
host: 'localhost',
models: [Product],
});

// Set up Express with OData
const app = express();
const productController = new ODataControler({
model: Product,
allowedMethod: ['get', 'post', 'patch', 'delete'],
});
new ExpressRouter(app, {
controllers: [productController],
dataSource
});

app.listen(3000);

// Query examples:
// GET /Product?$filter=price gt 50
// GET /Product?$orderby=price desc&$top=5
// GET /Product?$select=name,price
// GET /$metadata