File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /*
3+ * (c) Api Postcode <info@api-postcode.nl>
4+ *
5+ * For the full copyright and license information, please view the LICENSE
6+ * file that was distributed with this source code.
7+ */
8+
9+ namespace ApiPostcode \PostcodeBundle \Controller ;
10+
11+ use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
12+ use Symfony \Component \HttpFoundation \JsonResponse ;
13+ use Symfony \Component \HttpFoundation \Request ;
14+ use Symfony \Component \HttpFoundation \Response ;
15+
16+ /**
17+ * Class PostcodeController
18+ *
19+ * (c) Api Postcode <info@api-postcode.nl>
20+ */
21+ class PostcodeController extends Controller
22+ {
23+ /**
24+ * @param Request $request
25+ *
26+ * @return JsonResponse
27+ */
28+ public function fetchAction (Request $ request )
29+ {
30+ try {
31+ $ postcode = $ request ->get ('zipcode ' );
32+ $ houseNumber = $ request ->get ('number ' );
33+
34+ $ address = $ this ->get ('api.postcode.client ' )->fetchAddress ($ postcode , $ houseNumber );
35+
36+ return new JsonResponse ($ address ->toArray ());
37+ } catch (\Exception $ exception ) {
38+ return new JsonResponse (['message ' => $ exception ->getMessage ()], Response::HTTP_SERVICE_UNAVAILABLE );
39+ }
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments