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 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. diff --git a/README.md b/README.md index e69de29..c6da429 100644 --- a/README.md +++ 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 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.` + }); } });