Backend server for Travel Planner app. Performs CRUD operations on the Travel Planner database via REST APIs.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
This project is the Travel Planner backend server that's responsible for integrating the Travel Planner frontend app with the MySQL database that persists data. It does this by providing REST API endpoints to allow the frontend app to perform CRUD operations on the database.
To get a local copy up and running follow these simple steps.
You will need the following software installed in your environment to run this app.
- Clone the repo
git clone https://github.com/jakec-dev/travel-planner-server.git
- Install packages
yarn install
- Create an
.env
file in the project root directory and enter your database configuration settingsDB_HOST=database.example.com DB_DATABASE=database-name DB_USER=username DB_PASSWORD=password
- Start the server
yarn start
This API is designed to be used in conjunction with the Travel Planner App. It provides the following functionality:
Send a POST request to /items
. The request body should contain the new item, for example:
{
"name": "New item name",
"brand": "New item brand (optional)"
}
JavaScript/React example:
const SERVER_URL = "https://api.example.com";
const createItem = async (newItem) => {
try {
const resp = await fetch(`${SERVER_URL}/items`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(newItem),
}).then((res) => res.json());
if (resp.status === "error") {
throw Error(resp.message);
}
return resp.data;
} catch (err) {
throw Error(err);
}
};
const result = createItem({
name: "New item name",
brand: "New item brand",
})
.then((resp) => resp)
.catch((err) => console.log(err));
Send a PUT request to /items
. The request body should contain the modified item. The modified item will entirely replace the original item, rather than merge fields, so be sure to merge any existing fields before sending the request. For example:
{
"id": 3,
"name": "Original item name",
"brand": "Updated item brand"
}
JavaScript/React example:
const SERVER_URL = "https://api.example.com";
const updateItem = async (modifiedItem) => {
try {
const resp = await fetch(`${SERVER_URL}/items`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(modifiedItem),
}).then((res) => res.json());
if (resp.status === "error") {
throw Error(resp.message);
}
return resp.data;
} catch (err) {
throw Error(err);
}
};
const result = updateItem({
id: 3,
name: "Original item name",
brand: "Updated item brand",
})
.then((resp) => resp)
.catch((err) => console.log(err));
Send a DELETE request to /items/:id
, where :id
is the ID of the item to be deleted. No request body is required.
JavaScript/React example:
const SERVER_URL = "https://api.example.com";
const deleteItem = async (id) => {
try {
const resp = await fetch(`${SERVER_URL}/items/${id}`, {
method: "DELETE",
}).then((res) => res.json());
if (resp.status === "error") {
throw Error(resp.message);
}
return resp.data;
} catch (err) {
throw Error(err);
}
};
const result = deleteItem(4)
.then((resp) => resp)
.catch((err) => console.log(err));
Send a GET request to /items/:id
, where :id
is the ID of the item to be fetched. No request body is required.
JavaScript/React example:
const SERVER_URL = "https://api.example.com";
const fetchItem = async (itemId) => {
try {
const resp = await fetch(`${SERVER_URL}/items/${itemId}`).then((res) =>
res.json()
);
if (resp.status === "error") {
throw Error(resp.message);
}
return resp.data;
} catch (err) {
throw Error(err);
}
};
const result = fetchItem(2)
.then((resp) => resp)
.catch((err) => console.log(err));
Send a GET request to /items
. No request body is required.
JavaScript/React example:
const SERVER_URL = "https://api.example.com";
const fetchAllItems = async (itemId) => {
try {
const resp = await fetch(`${SERVER_URL}/items`).then((res) => res.json());
if (resp.status === "error") {
throw Error(resp.message);
}
return resp.data;
} catch (err) {
throw Error(err);
}
};
const result = fetchAllItems()
.then((resp) => resp)
.catch((err) => console.log(err));
Navigate to /api-docs
in a web browser.
- Create database connection
- Add route, controller, service and data layers for items
- Add API documentation
- Write unit and integration tests
- Write project documentation
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project uses Mocha, Chai, and Sinon for testing, and Istanbul for test coverage reports
yarn test
This project uses ESLint for linting using AirBNB's style guide, and Prettier for formatting.
yarn lint
yarn lint:fix
yarn format
yarn format:write
Distributed under the MIT License. See LICENSE.txt
for more information.
Jake Clayton
w: jakec.dev