File tree Expand file tree Collapse file tree 3 files changed +63
-2
lines changed
Expand file tree Collapse file tree 3 files changed +63
-2
lines changed Original file line number Diff line number Diff line change 11Postcode.nl Api Client
22=============
33
4- PHP Api client for the [ Postcode.nl Api] ( https://api.postcode.nl/documentation/ ) .
4+ PHP Api client for the [ Postcode.nl Api] ( https://api.postcode.nl/documentation/ ) .
55
66
77How to install
88=============
99
1010### Composer
1111
12- Get package ` postcode-nl/api-client ` .
12+ Get package ` postcode-nl/api-client ` .
1313
1414### From this repository
1515
Original file line number Diff line number Diff line change 1+ Example Postcode.nl Api Proxy
2+ =============
3+
4+ PHP Api proxy for the [ Postcode.nl Api] ( https://api.postcode.nl/documentation/ ) .
5+
6+
7+ Usage
8+ =============
9+
10+ This directory serves as an extremely simple proxy example for the supplied client.
11+ Set the correct ` API_KEY ` and ` API_SECRET ` and optional ` PLATFORM ` and you can call
12+ any supported method, for example:
13+
14+ ### Show all valid data from a valid postal code
15+ ` .../example/index.php?action=dutchAddressByPostcode&data[]=2012es&data[]=30 `
16+
17+ ### Return an exception for non-existing addresses
18+ ` .../example/index.php?action=dutchAddressByPostcode&data[]=2012es&data[]=31 `
19+
20+ ### Show autocomplete results for a German lookup
21+ ` .../example/index.php?action=internationalAutocomplete&data[]=deu&data[]=strasse&data[]=CLIENT_SESSION_FROM_COOKIE `
22+
23+ Please only use this proxy as an example for your own implementation.
24+ What you should add:
25+
26+ * Don't allow random calls but implement what you use in a custom wrapper
27+ * Add caching to prevent fetching the same data over and over
28+ * Add Session by reading ` $_COOKIE ` , don't pass it in the URL
29+
30+ License
31+ =============
32+
33+ The code is available under the Simplified BSD License, see the included LICENSE file.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ define ('API_KEY ' , /* as received by mail after signing up */ );
4+ define ('API_SECRET ' , /* as received by mail after signing up */ );
5+ define ('PLATFORM ' , 'example proxy ' );
6+
7+
8+ // this will load exceptions when they occur
9+ spl_autoload_register (function ($ class ){
10+ if (0 === strpos ($ class , 'PostcodeNl \\' ))
11+ require (__DIR__ .'/../src/ ' . str_replace ('\\' , '/ ' , $ class ) .'.php ' );
12+ });
13+
14+ header ('Content-Type: application/json ' );
15+
16+ try
17+ {
18+ if (0 !== strpos ($ _GET ['action ' ], 'international ' ) && 0 !== strpos ($ _GET ['action ' ], 'dutchAddress ' ))
19+ throw new Exception ('This example only supports calls to international or dutchAddress methods ' );
20+
21+ $ client = new PostcodeNl \Api \Client (API_KEY , API_SECRET , PLATFORM );
22+ print json_encode (call_user_func_array ([$ client , $ _GET ['action ' ]], $ _GET ['data ' ] ?? []));
23+ }
24+ catch (Exception $ e )
25+ {
26+ http_response_code (400 );
27+ print json_encode (['Exception ' => $ e ->getMessage ()]);
28+ }
You can’t perform that action at this time.
0 commit comments