A web server which returns data associated with a key based on its similarity with a given string, by querying a MongoDB database
- Install node.js, yarn, mongodb.
- Configure
mongodb
so its server is running. - Clone this repository, and using a terminal navigate to its directory.
- Run
yarn
to install the dependencies.
- Copy the contents of the
.env.example
file to a.env
next to it, and edit it with your values.- Set
MONGODB_CONNECTION_STRING
to the connection string to be used to connect to the mongodb database. - Set
SERVER_PORT
to the port the server listen to.
- Set
- Run
yarn build
to build the files. - Run
yarn start
to start the application.
- You can run
yarn dev
to combine the 2 steps above, while listening to changes and restarting automatically.- You need to run
yarn global add ts-node
once for this to run.
- You need to run
- Run
yarn lint
to lint the code. - Run
yarn format
to format the code.
GET /:group/:searchString
- The data to be returned will belong to the given
group
. - The
key
of the object whose data will be returned will be the one which is most similar to the givensearchString
exaple request url
GET /countries/Greeec/
exaple response
{
"key": "Greece",
"similarity": 0.65,
"data": [
{
"name": "population",
"value": "10.72m"
},
{
"name": "size",
"value": "131.957 sq m"
}
]
}
POST /:group/
- The data to be created will belong to the given
group
.
example request url
POST /countries/
example request body (creating one entry):
{
"data": {
"key": "Greece",
"data": [
{
"name": "population",
"value": "10.72m"
},
{
"name": "size",
"value": "131.957 sq m"
}
]
}
}
example request body (creating multiple entries):
{
"data": [
{
"key": "Cyprus",
"data": [
{
"name": "population",
"value": "1.189m"
},
{
"name": "size",
"value": "9.251 sq m"
}
]
},
{
"key": "Greece",
"data": [
{
"name": "population",
"value": "10.72m"
},
{
"name": "size",
"value": "131.957 sq m"
}
]
}
]
}
The response has a status of 204
with no content.
DELETE /:group/
- All data of the given
group
will be deleted.
example request url
DELETE /countries/
The response has a status of 204
with no content.