Class ApiConfig

ApiConfig provides methods and properties for configuring API parameters.

Name Description
Properties
authMethod Get or set the authentication method.
defaultServerUrl Get the default server URL-
serverUrl Get or set the API server URL.
Methods
getCredentials Gets the credentials.
setCredentials Set the credentials.

Properties

authMethod:string

Get or set the authentication method.

JOSM uses two authentication methods:

basic
Basic authentication with a username and a password
oauth
Authentication with the OAuth protocol.

var conf = require("josm/api").ApiConfig;
conf.authMethod;   // -> the current authentication method

// set OAuth as authentication method
conf.authMethod = "oauth";

defaultServerUrl:string

Get the default server URL.

var conf = require("josm/api").ApiConfig;
conf.defaultServerUrl;   // -> the default server url

serverUrl:string

Get or set the API server URL.

get
Replies the currently configured server URL or undefinend, if no server URL is configured.
set
Sets the current server URL. If null or undefined, removes the current configuration. Accepts either a string or a URL. Only accepts http or https URLs.

var conf = require("josm/api").ApiConfig;
conf.serverUrl;   // -> the current server url

// set a new API url
conf.serverUrl = "http://api06.dev.openstreetmap.org";  

Functions

getCredentials:object

Gets the credentials, i.e. username and password for the basic authentication method.

Named options
host:string
The host name of the API server for which credentials are retrieved. If missing, the host name of the currently configured OSM API server is used.

Parameters

Name Type Description
authMethod string the authentication method. Either "basic" or "oauth".
options object (optional) additional options (see above)

Examples

var conf = require("josm/api").ApiConfig;

// get username/password for the current OSM API server 
var credentials = conf.getCredentials("basic");

setCredentials:object

Set the credentials, i.e. username and password for the basic authentication method.

Basic authentication credentials are either an instance of java.net.PasswordAuthentication or an object {user: string, password: string}.

OAuth authentication credentials are either an instance of OAuthToken or an object {key: string, secret: string}.

Named options
host:string
The host name of the API server for which credentials are set. If missing, the host name of the currently configured OSM API server is used.

Parameters

Name Type Description
authMethod string the authentication method. Either "basic" or "oauth".
credentials object the credentials.
options object (optional) additional options (see above)

Examples

var conf = require("josm/api").ApiConfig;

// set the credentials
conf.setCredentials("basic", {user:"test", password:"apassword"});