Welcome to Northcoders News API! This respository contains database which consists of files with various articles, users, topics and comments. The API allows for comments to be added to articles and articles to be added to topics. It also allows user to vote up or down for both articles and comments. For more information about available endpoints please check Routes section.
Clone this repository using command below:
$ git clone https://github.com/dsobkow/BE2-northcoders-news
Navigate to cloned repository and install all dependencies and dev dependencies on your computer:
$ npm install
This will install the following packages:
Dependencies:
- body-parser: ^1.18.3
- ejs: ^2.6.1
- express: ^4.16.3
- mongoose: ^5.2.8
Dev dependencies:
- chai: ^4.1.2
- mocha: ^5.2.0
- nodemon: ^1.18.3
- supertest: ^3.1.0
This repositiory is missing a config folder that exports the value of DB_URL depending on the process.env.NODE_ENV. Create config directory in your project root and add a config.js file that looks like this:
process.env.NODE_ENV = process.env.NODE_ENV || "development";
const config = {
development: {
DB_URL: "mongodb://localhost:27017/northcoders_news",
},
test: {
DB_URL: "mongodb://localhost:27017/northcoders_news_test",
},
production: {
DB_URL: "your mlab url containing username and password",
},
};
module.exports = config[process.env.NODE_ENV];Make sure that you have MongoDB installed:
$ mongo --version
Start MongoDB in separate terminal:
$ mongod
Then seed the database in your integrated terminal:
$ npm run seed:dev
And start your local server:
$ npm run dev
You should see this in your terminal:
listening on 9090...
connected to mongodb://localhost:27017/northcoders_news...
Now you are ready to open the app in your browser or Postman with this URL:
localhost:9090/api
If you would like to run tests you need to stop server from listening using Ctrl+C command. Now run this command in your integrated terminal:
$ npm t
The following endpoints are available:
GET /apiHomepage
GET /api/topicsGets all the topics
GET /api/topics/:topic_slug/articlesReturns all the articles for a certain topic, e.g: /api/topics/football/articles
POST /api/topics/:topic_slug/articlesAdds a new article to a topic. This route requires a JSON body with title and body key value pairs
e.g: { "title": "new article", "body": "This is my new article content"}
GET /api/articlesReturns all the articles
GET /api/articles/:article_idGets an individual article
GET /api/articles/:article_id/commentsGets all the comments for a individual article
POST /api/articles/:article_id/commentsAdds a new comment to an article. This route requires a JSON body with body and created_by key value pairs
e.g: {"body": "This is my new comment", "created_by": <mongo id for a user>}
PUT /api/articles/:article_idIncrements or decrements the votes of an article by one. This route requires a vote query of 'up' or 'down'
e.g: /api/articles/:article_id?vote=up
PUT /api/comments/:comment_idIncrements or decrements the votes of a comment by one. This route requires a vote query of 'up' or 'down'
e.g: /api/comments/:comment_id?vote=down
DELETE /api/comments/:comment_idDeletes a comment
GET /api/users/:usernamee.g: /api/users/mitch123
Returns a JSON object with the profile data for the specified user.