Skip to content
apazureck edited this page Jun 5, 2017 · 4 revisions

Create Interfaces

  1. Create a file you want to put your interfaces to.
  2. Execute the Create Interfaces from OData V4.0 Service command.
  3. Fill in the url of your odata service (starting with http://). Use base path to get the metadata! For example: http://localhost:2200/moviedb
  4. Select if you want to generate a modular or ambient declaration of your interfaces.

The output should look like this:

/**************************************************************************
Created by odatatools: https://marketplace.visualstudio.com/items?itemName=apazureck.odatatools
Use Command 'odata: xyUpdate to refresh data while this file is active in the editor.
Creation Time: Mon Jun 05 2017 23:46:29 GMT+0200 (Mitteleuropäische Sommerzeit)
DO NOT DELETE THIS IN ORDER TO UPDATE YOUR SERVICE
#ODATATOOLSOPTIONS
{
	"source": "http://localhost:2200/moviedb/$metadata",
	"modularity": "Ambient",
	"requestOptions": {}
}
#ODATATOOLSOPTIONSEND
**************************************************************************/

declare namespace ODataTestService.Models {
    export interface Movie {
        Id: Edm.Int32;
        LenderId: Edm.Int32;
        ...

Create Proxy Client

  1. Create a file you want to put your proxy to.
  2. Execute the Create Proxy from OData V4.0 Service command.
  3. Fill in the url of your odata service (starting with http://). Use base path to get the metadata! For example: http://localhost:2200/moviedb
  4. Select if you want to generate a modular or ambient declaration of your interfaces.

The output should look like this:

/**************************************************************************
Created by odatatools: https://marketplace.visualstudio.com/items?itemName=apazureck.odatatools
Use Command 'odata: xyUpdate to refresh data while this file is active in the editor.
Creation Time: Mon Jun 05 2017 22:59:23 GMT+0200 (Mitteleuropäische Sommerzeit)
DO NOT DELETE THIS IN ORDER TO UPDATE YOUR SERVICE
#ODATATOOLSOPTIONS
{
	"modularity": "Modular",
	"requestOptions": {},
	"source": "http://localhost:2200/moviedb/$metadata"
}
#ODATATOOLSOPTIONSEND
**************************************************************************/

import { ProxyBase, EntitySet } from './odataproxybase';
import * as odatajs from './odatajs';

export class MovieContainer extends ProxyBase {
    constructor(address: string, name?: string, additionalHeaders?: odatajs.Header) {
        super(address, name, additionalHeaders);
        this.Movies = new MovieEntitySet("Movies", address, "Id", additionalHeaders);
        this.Customers = new EntitySet<ODataTestService.Models.Customer>("Customers", address, "Id", additionalHeaders);
        this.Addresses = new EntitySet<ODataTestService.Models.Address>("Addresses", address, "Id", additionalHeaders);
    }
    Movies: MovieEntitySet;
    ...

In additions some files will be copied:

  1. odatajs.js is a java script odata client, which is used by the proxy to send requests. (May be replaced in future releases)
  2. odataproxybase.ts contains base classes for your generated proxy client.
  3. odatajs.d.ts is generated if you are using "Modular" generation.

Update and Header Manipulation

If you are trying to update in an empty file, you will get a default header:

/**************************************************************************
Created by odatatools: https://marketplace.visualstudio.com/items?itemName=apazureck.odatatools
Use Command 'odata: xyUpdate to refresh data while this file is active in the editor.
Creation Time: Mon Jun 05 2017 22:59:23 GMT+0200 (Mitteleuropäische Sommerzeit)
DO NOT DELETE THIS IN ORDER TO UPDATE YOUR SERVICE
#ODATATOOLSOPTIONS
{
	"modularity": "Ambient",
	"requestOptions": {},
	"source": "unknown"
}
#ODATATOOLSOPTIONSEND
**************************************************************************/

You always can modify the header and re-update your service. You can use the #ODATATOOLSOPTIONS ... #ODATATOOLSOPTIONSEND section to do so.

The options are saved as json and stored at the top of the generated file.

  • modularity: can be set to "Ambient" or "Modular" to create ambient or modular versions. Ambient versions are used for browsers and modular versions can be used for example node.js applications or asynchronous module loading.
  • source: is the full url used by odatatools to request the metadata from your service, so $metadata is always given at the end of the string. If you are not using the create commands you always have to give the full url.
  • requestOptions: allows to set additional options. The generators are using the request module for node.js. You can use all options provided there:
interface CoreOptions {
    baseUrl?: string;
    callback?: (error: any, response: IncomingMessage, body: any) => void;
    jar?: boolean | CookieJar;
    formData?: any; // Object
    form?: any; // Object or string
    auth?: AuthOptions;
    oauth?: OAuthOptions;
    aws?: AWSOptions;
    hawk?: HawkOptions;
    qs?: any;
    json?: any;
    multipart?: RequestPart[] | Multipart;
    agentOptions?: any;
    agentClass?: any;
    forever?: any;
    host?: string;
    port?: number;
    method?: string;
    headers?: Headers;
    body?: any;
    followRedirect?: boolean | ((response: IncomingMessage) => boolean);
    followAllRedirects?: boolean;
    maxRedirects?: number;
    encoding?: string;
    pool?: any;
    timeout?: number;
    proxy?: any;
    strictSSL?: boolean;
    gzip?: boolean;
    preambleCRLF?: boolean;
    postambleCRLF?: boolean;
    key?: Buffer;
    cert?: Buffer;
    passphrase?: string;
    ca?: Buffer;
    har?: HttpArchiveRequest;
    useQuerystring?: boolean;
  }

See the Request site for more information on the usage of those properties.

Clone this wiki locally