Skip to content

Update CDS OData V2 Adapter (Node.js) #1118

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions advanced/odata.md
Original file line number Diff line number Diff line change
Expand Up @@ -1324,42 +1324,20 @@ Since singletons represent a one-element entity, a `POST` request is not suppor

While CAP defaults to OData V4, the latest protocol version, some projects need to fallback to OData V2, for example, to keep using existing V2-based UIs.

### Enabling OData V2 via Proxy in Node.js Apps { #odata-v2-proxy-node}
### Enabling OData V2 via CDS OData V2 Adapter in Node.js Apps { #odata-v2-adapter-node}

CAP Node.js supports serving the OData V2 protocol through the [_OData V2 adapter for CDS_](https://www.npmjs.com/package/@cap-js-community/odata-v2-adapter), which translates between the OData V2 and V4 protocols.

For Node.js projects, add the proxy as express.js middleware as follows:
For Node.js projects, add the CDS OData V2 adapter as express.js middleware as follows:

1. Add the adapter package to your project:

```sh
npm add @cap-js-community/odata-v2-adapter
```

2. Add this as a plugin to your project:

::: code-group
```json [package.json]
{...
"cds" : {
"cov2ap" : {
"plugin" : true
}
}
}
```

```json [.cdsrc.json]
{
"cov2ap" : {
"plugin" : true
}
}
```
:::

3. Access OData V2 services at [http://localhost:4004/v2/${path}](http://localhost:4004/v2).
4. Access OData V4 services at [http://localhost:4004/${path}](http://localhost:4004) (as before).
2. Access OData V2 services at [http://localhost:4004/odata/v2/${path}](http://localhost:4004/odata/v2).
3. Access OData V4 services at [http://localhost:4004/odata/v4/${path}](http://localhost:4004/odata/v4) (as before).

Example: Read service metadata for `CatalogService`:

Expand All @@ -1370,8 +1348,8 @@ Example: Read service metadata for `CatalogService`:
service CatalogService { ... }
```

- OData V2: `GET http://localhost:4004/v2/browse/$metadata`
- OData V4: `GET http://localhost:4004/browse/$metadata`
- OData V2: `GET http://localhost:4004/odata/v2/browse/$metadata`
- OData V4: `GET http://localhost:4004/odata/v4/browse/$metadata`

[Find detailed instructions at **@cap-js-community/odata-v2-adapter**.](https://www.npmjs.com/package/@cap-js-community/odata-v2-adapter){.learn-more}

Expand Down