UNPKG

4.6 kBMarkdownView Raw
1<h1 align="center">
2 <img src="https://img.ideal-postcodes.co.uk/PAF%20API%20Logo@3x.png" alt="PAF API">
3</h1>
4
5> HTTP API that parses Postcode Address File records into correctly formatted address lines
6
7[![CircleCI](https://circleci.com/gh/ideal-postcodes/paf-api.svg?style=svg)](https://circleci.com/gh/ideal-postcodes/paf-api)
8[![Dependency Status](https://david-dm.org/ideal-postcodes/paf-api.png)](https://david-dm.org/ideal-postcodes/paf-api)
9[![Coverage Status](https://coveralls.io/repos/github/ideal-postcodes/paf-api/badge.svg?branch=master)](https://coveralls.io/github/ideal-postcodes/paf-api?branch=master)
10
11[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/ideal-postcodes/paf-api)
12
13Parses Postcode Address File records into correctly formatted address recognised by Royal Mail according to its Clear Addressing Guidelines.
14
15Produces consistent address lines, a post town line and a postcode line via HTTP
16
17## Features
18
19- Exposes [UK Clear Addressing](https://github.com/ideal-postcodes/uk-clear-addressing) as a HTTP service
20- Deployable as a docker container or node.js application
21
22![Correct Addressing](https://img.ideal-postcodes.co.uk/correct_address.gif)
23
24## Links
25
26- [Github Repository](https://github.com/ideal-postcodes/paf-api)
27- [Test Live on paf-api.ideal-postcodes.dev](https://paf-api.ideal-postcodes.dev)
28- [Docker Hub Image](https://hub.docker.com/r/idealpostcodes/paf-api)
29- [UK Clear Addressing Project](https://github.com/ideal-postcodes/uk-clear-addressing)
30- [NPM Package](https://www.npmjs.com/package/paf-api)
31- [More information on Postcode Address File data attributes](https://ideal-postcodes.co.uk/documentation/paf-data)
32- [PAF Programmer's Guide](https://js.ideal-postcodes.co.uk/guide.pdf)
33
34## Getting Started
35
36Try on [paf-api.ideal-postcodes.dev](https://paf-api.ideal-postcodes.dev)
37
38```bash
39curl -X POST \
40 http://paf-api.ideal-postcodes.dev/parse \
41 -H 'Content-Type: application/json' \
42 -d '{ "sub_building_name": "Flat 8", "building_name": "Oxford House 110-114", "thoroughfare_name": "High Street" }'
43```
44
45### HTTP API Usage
46
47This API responds to `POST` requests to `/parse` with a JSON payload representing a PAF Record
48
49#### `POST /parse`
50
51##### Request
52
53```json
54POST /parse
55
56{
57 "postcode": "WS11 5SB",
58 "post_town": "CANNOCK",
59 "thoroughfare": "Pye Green Road",
60 "building_name": "Flower House 189A",
61 "organisation_name": "S D Alcott Florists",
62}
63```
64
65##### Response
66
67```json
68{
69 "query": {
70 "postcode": "WS11 5SB",
71 "post_town": "CANNOCK",
72 "thoroughfare": "Pye Green Road",
73 "building_name": "Flower House 189A",
74 "organisation_name": "S D Alcott Florists",
75 "building_number": "",
76 "sub_building_name": "",
77 "dependant_locality": "",
78 "double_dependant_locality": "",
79 "dependant_thoroughfare": "",
80 "po_box": "",
81 "department_name": "",
82 },
83 "formatted": {
84 "postcode": "WS11 5SB",
85 "post_town": "CANNOCK",
86 "line_1": "S D Alcott Florists",
87 "line_2": "Flower House",
88 "line_3": "189a Pye Green Road",
89 "premise": "Flower House, 189a"
90 }
91}
92```
93
94#### Available Payload Attributes
95
96```javascript
97{
98 building_number: string | number;
99 building_name: string;
100 sub_building_name: string;
101 dependant_locality: string;
102 double_dependant_locality: string;
103 thoroughfare: string;
104 dependant_thoroughfare: string;
105 po_box: string;
106 post_town: string;
107 postcode: string;
108 department_name: string;
109 organisation_name: string;
110}
111```
112
113### Deploy
114
115#### Deploy as a docker container
116
117Using the docker CLI
118
119```
120docker pull ideal-postcoes/paf-api:latest
121
122docker run -p 8080:8080 ideal-postcodes/paf-api
123```
124
125Alternatively with docker-compose
126
127```bash
128git clone https://github.com/ideal-postcodes/paf-api && cd paf-api
129
130docker-compose up -d
131```
132
133#### Deploy as a node.js process
134
135Requires node.js 8 or above
136
137```bash
138git clone https://github.com/ideal-postcodes/paf-api && cd paf-api && npm install
139
140npm start # Traffic served on 8080
141```
142
143#### NPM Module
144
145The npm module exports an express app factory which takes a `pino` logger
146
147```javascript
148const { App } = require("paf-api");
149
150const app = App({ logger: pino() });
151
152http.createServer(app).listen(PORT);
153```
154
155#### Configuration
156
157The following environment variables can be passed to the application.
158
159```bash
160PORT=8080 # Sets the port to listen on
161```
162
163## Licence
164
165MIT
166