API Reference
class DeclaredAPI
method getURL
Purpose
Get the URL for the APIUsage
This function requires base URL to be configured in order to work.
As path parameters are considered to be a part of the URL, their values must be provided to the getAPI call and they are injected in to the URL.
Query parameters are optionally included, too.
Parameters
Name | Type | Description |
---|---|---|
pathAndQueryParams | Object | Path parameters value for the API, or combination of path and query parameter values. |
Returns
stringExamples
Older styles are still supported in later versions, just not preferred.
Path only
import { APIDeclaration } from 'papupata'
const api = new APIDeclaration()
api.configure({baseURL: 'https://example.com'})
const myAPI = api.declarePostAPI('/do-stuff/:param')
.params({param: String})
.response<string>()
const URL = myAPI.getURL({param: 'value'})
// URL is now https://example.com/do-stuff/value
Path and query (query omitted)
import { APIDeclaration } from 'papupata'
const api = new APIDeclaration()
api.configure({baseURL: 'https://example.com'})
const myAPI = api.declarePostAPI('/do-stuff/:param')
.params({param: String})
.query({qval: String})
.response<string>()
const URL = myAPI.getURL({param: 'value'})
// URL is now https://example.com/do-stuff/value
Path and query (query present)
import { APIDeclaration } from 'papupata'
const api = new APIDeclaration()
api.configure({baseURL: 'https://example.com'})
const myAPI = api.declarePostAPI('/do-stuff/:param')
.params({param: String})
.query({qval: String})
.response<string>()
const URL = myAPI.getURL({param: 'value', qval: 'hello'})
// URL is now https://example.com/do-stuff/value?qval=hello