-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (41 loc) · 1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const express = require('express'),
data_json = require('./postalcode.json')
app = express()
app.get('/api/postcode/:code', (req, res)=>{
let code = req.params.code
let data = PostName(code)
if(data){
res.send(data)
}else{
res.send("No Post Office Found in this code")
}
})
app.get('/api/postname/:name', (req, res)=>{
let name = req.params.name
let data = PostCode(name)
if(data){
res.send(data)
}else{
res.send("No Post office found with Matching name, Enter Currect name. Eg: Achalapur B.O")
}
})
app.get('*', (req, res)=>{
res.send("No Such EndPoint")
})
app.listen(8080)
function PostName(code) {
for (var i = 0; i < data_json.length; i++) {
if (data_json[i].pincode == code) {
return data_json[i]
}
}
return false
}
function PostCode(name) {
for (var i = 0; i < data_json.length; i++) {
if (data_json[i].officename == name) {
return data_json[i]
}
}
return false
}