-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(example-todo): add Geo to examples/todo
Show how to use REST services (US Census Geocoder) in LB4 apps.
- Loading branch information
Showing
14 changed files
with
327 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"connector": "rest", | ||
"options": { | ||
"headers": { | ||
"accept": "application/json", | ||
"content-type": "application/json" | ||
} | ||
}, | ||
"operations": [ | ||
{ | ||
"template": { | ||
"method": "GET", | ||
"url": "https://geocoding.geo.census.gov/geocoder/locations/onelineaddress", | ||
"query": { | ||
"format": "{format=json}", | ||
"benchmark": "Public_AR_Current", | ||
"address": "{address}" | ||
}, | ||
"responsePath": "$.result.addressMatches[*].coordinates" | ||
}, | ||
"functions": { | ||
"geocode": ["address"] | ||
} | ||
} | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright IBM Corp. 2017,2018. All Rights Reserved. | ||
// Node module: @loopback/example-todo | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {inject} from '@loopback/core'; | ||
import {juggler, DataSource} from '@loopback/repository'; | ||
const config = require('./geocoder.datasource.json'); | ||
|
||
export class GeocoderDataSource extends juggler.DataSource { | ||
static dataSourceName = 'geocoder'; | ||
|
||
constructor( | ||
@inject('datasources.config.geocoder', {optional: true}) | ||
dsConfig: DataSource = config, | ||
) { | ||
dsConfig = Object.assign({}, dsConfig, { | ||
// A workaround for the current design flaw where inside our monorepo, | ||
// packages/service-proxy/node_modules/loopback-datasource-juggler | ||
// cannot see/load the connector from | ||
// examples/todo/node_modules/loopback-connector-rest | ||
connector: require('loopback-connector-rest'), | ||
}); | ||
super(dsConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright IBM Corp. 2017,2018. All Rights Reserved. | ||
// Node module: @loopback/example-todo | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {getService, juggler} from '@loopback/service-proxy'; | ||
import {inject, Provider} from '@loopback/core'; | ||
import {GeocoderDataSource} from '../datasources/geocoder.datasource'; | ||
|
||
export interface GeoPoint { | ||
/** | ||
* latitude | ||
*/ | ||
y: number; | ||
|
||
/** | ||
* longitude | ||
*/ | ||
x: number; | ||
} | ||
|
||
export interface GeocoderService { | ||
geocode(address: string): Promise<GeoPoint[]>; | ||
} | ||
|
||
export class GeocoderServiceProvider implements Provider<GeocoderService> { | ||
constructor( | ||
@inject('datasources.geocoder') | ||
protected datasource: juggler.DataSource = new GeocoderDataSource(), | ||
) {} | ||
|
||
value(): GeocoderService { | ||
return getService(this.datasource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright IBM Corp. 2017,2018. All Rights Reserved. | ||
// Node module: @loopback/example-todo | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
export * from './geocoder.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.