RESTful NodeJS web application with a single endpoint to parse XML information from a text source and return the relevant data.
The endpoint /parse-content
will accept a POST
request containing, in the request body, the plain text content to be parsed.
The expected responses from the endpoint are:
-
200
- If the application was able to parse the data.- The response body will include a JSON object with the formatted data.
-
400
- If the request can not be fulfilled because of a client error (a malformed XML content, for example).- The same error will be returned if the content does not satisfy the following conditions:
- Opening tags without a corresponding closing tag.
- Missing
<total>
tag and/or value. - Missing
<cost_centre>
tag and/or value.
- The same error will be returned if the content does not satisfy the following conditions:
-
500
- If something went wrong on the API side.- A readable message will be returned to the client with non-technical details.
This is a NodeJS application using Express and was bootstrapped using the Express generator tool.
- Clone this repo
- CD into the folder
- The app will use port
3001
by default. You can change this setting by setting up an environment variablePORT={port#}
or changing the default port on the file/bin/www:15
. - Set NODE_ENV to
“production”
. - Run
npm install
. - Finally
npm start
to start the app. - You can start consuming the endpoint using
http://localhost:{port}/parse-content
.