From 631cc042465b5d01f87e79ce4ca96eaca841e37b Mon Sep 17 00:00:00 2001 From: Brian Schnee <77141303+brianschnee@users.noreply.github.com> Date: Mon, 13 Jun 2022 00:37:00 -0400 Subject: [PATCH 1/5] Create LICENSE.md --- LICENSE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..fb48127 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 the-api-administration + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 4610bf6f30ad54e548238f8246eb7666d05f0ad4 Mon Sep 17 00:00:00 2001 From: Brian Schnee <77141303+brianschnee@users.noreply.github.com> Date: Mon, 13 Jun 2022 01:19:15 -0400 Subject: [PATCH 2/5] Delete README.md --- README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index e69de29..0000000 From 7f3ad0043432aa0226bc2307d2072cda511ee3a7 Mon Sep 17 00:00:00 2001 From: Brian Schnee <77141303+brianschnee@users.noreply.github.com> Date: Mon, 13 Jun 2022 01:19:50 -0400 Subject: [PATCH 3/5] Create README.md --- README.md | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c6da429 --- /dev/null +++ b/README.md @@ -0,0 +1,154 @@ +# Coding-Resources-API + +
+ +[![Contributors][contributors-shield]][contributors-url] +[![Forks][forks-shield]][forks-url] +[![Stargazers][stars-shield]][stars-url] +[![Issues][issues-shield]][issues-url] +[![MIT License][license-shield]][license-url] + + +
+
+ + Logo + + +

Coding Resources API

+ +

+ Provides Coding Resources +
+ Explore the docs » +
+
+ View Demo + · + Report Bug + · + Request Feature +

+
+ + +
+ Table of Contents +
    +
  1. + About The Project + +
  2. +
  3. Getting Started
  4. +
  5. Usage
  6. +
  7. Roadmap
  8. +
  9. Contributing
  10. +
  11. License
  12. +
  13. Acknowledgments
  14. +
+
+ + + +## About The Project + +Search for coding resources by relevant keywords. This API serves educational content for a wide variety of computer science topics, languages and technologies relevant to web development. + +

(back to top)

+ +### Built With + +- EJS +- CSS +- JavaScript +- Node.js +- Express + +

(back to top)

+ + + +## Getting Started + +Simply visit: https://coding-resources-api.herokuapp.com/ and read our documentation to learn how to interact with our API! If you would like to help us out, feel free to create issues through our github repo. + +

(back to top)

+ + + +## Usage + +Access our API endpoints to recieve coding resource data in JSON format. + +

(back to top)

+ + + +## Roadmap + +- [X] Add search functionality +- [ ] Offer more resources +- [ ] Support mobile devices +- [ ] Create more endpoints + +See the [open issues](https://github.com/the-api-administration/coding-resources-api/issues) for a full list of proposed features (and known issues). + +

(back to top)

+ + + +## Contributing + +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 to better our API, please fork the repo and create a pull request. Additionally, you can open an issue and offer advice. +Don't forget to give the project a star! Thanks again! + +1. Visit our Issues page to check if an issue exists and does not have an assignee. +2. Fork the Project +3. Change to your Feature Branch (`git checkout -b feature/AmazingFeature`) +4. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) +5. Push to the Branch (`git push origin feature/AmazingFeature`) +6. Open a Pull Request + +

(back to top)

+ + + +## License + +Distributed under the MIT License. See `LICENSE.md` for more information. + +

(back to top)

+ + + +## Acknowledgments + +- [@AlexisInTech](https://twitter.com/alexisintech) +- [@AlysshaLewin](https://twitter.com/AlysshaLewin) +- [@Asper_Jacob](https://twitter.com/asper_jacob) +- [@BrianSchneeDev](https://twitter.com/BrianSchneeDev) +- [@BytesByBianca](https://twitter.com/bytesbybianca) +- [@DanaMiteCoder](https://twitter.com/danamitecoder) +- [@Dev_Ethos](https://twitter.com/dev_ethos/) +- [@ErikaTeal_](https://twitter.com/erikateal_) +- [@JacobEGood](https://twitter.com/jacobegood) +- [@MoraCodes](https://twitter.com/moracodes) + +

(back to top)

+ + + +[contributors-shield]: https://img.shields.io/github/contributors/the-api-administration/coding-resources-api.svg?style=for-the-badge +[contributors-url]: https://github.com/the-api-administration/coding-resources-api/graphs/contributors +[forks-shield]: https://img.shields.io/github/forks/the-api-administration/coding-resources-api.svg?style=for-the-badge +[forks-url]: https://github.com/the-api-administration/coding-resources-api/network/members +[stars-shield]: https://img.shields.io/github/stars/the-api-administration/coding-resources-api.svg?style=for-the-badge +[stars-url]: https://github.com/the-api-administration/coding-resources-api/stargazers +[issues-shield]: https://img.shields.io/github/issues/the-api-administration/coding-resources-api.svg?style=for-the-badge +[issues-url]: https://github.com/the-api-administration/coding-resources-api/issues +[license-shield]: https://img.shields.io/github/license/the-api-administration/coding-resources-api.svg?style=for-the-badge +[license-url]: https://github.com/the-api-administration/coding-resources-api/blob/master/LICENSE.md From 041fdb83b42a879ef9cd9cf6d5eca20738003318 Mon Sep 17 00:00:00 2001 From: Erika <101034206+erikateal@users.noreply.github.com> Date: Mon, 13 Jun 2022 13:45:33 -0500 Subject: [PATCH 4/5] Create CONTRIBUTING.md added contributing file --- CONTRIBUTING.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..053c536 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,15 @@ + + +## Contributing + +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 to better our API, please fork the repo and create a pull request. Additionally, you can open an issue and offer advice. +Don't forget to give the project a star! Thanks again! + +1. Visit our Issues page to check if an issue exists and does not have an assignee. +2. Fork the Project +3. Change to your Feature Branch (`git checkout -b feature/AmazingFeature`) +4. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) +5. Push to the Branch (`git push origin feature/AmazingFeature`) +6. Open a Pull Request From faf3b38c59067490a460b6208ac89f392ca85a73 Mon Sep 17 00:00:00 2001 From: brianschnee Date: Mon, 13 Jun 2022 21:59:12 -0400 Subject: [PATCH 5/5] handled case where keyword doesnt exist --- server.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/server.js b/server.js index 765e7e5..4f85cc3 100644 --- a/server.js +++ b/server.js @@ -2,6 +2,8 @@ const express = require('express'); const app = express(); const cors = require('cors'); const { resources } = require("./resources"); +const { response } = require('express'); +const e = require('express'); const PORT = process.env.PORT || 8000; app.set('view engine', 'ejs') @@ -31,15 +33,14 @@ app.get('/api/:keyword', (req, res) => { // filter resources array, return items that match query; tag. const matches = resources.filter((obj) => obj.keywords.some(str => str.includes(keyword))); - try { - // if matches were found respond with json - if (matches.length) { - res.json(matches); - } else { - throw new Error('No resources found.'); - } - } catch(err) { - console.error(err); + // if matches were found, respond with matches array in JSON format + if (matches.length) { + res.json(matches); + } else { + // respond with status 404, no matches were found + res.status(404).json({ + error: `No resources were found with the ${keyword} keyword.` + }); } });