This repository serves to provide very basic /api functionality to present information concerning a false news application, containing users, comments, articles & topics.
Endpoints provide basic functionality as well as more dynamic options where users can refine their searches by article_id, comment_id, topic, etc. Users can also structure returned queries by using sort_by or order_by options on certain endpoints.
The base link for the hosted api is below:
https://nc-news-acw.onrender.com
The numerous endpoints are listed here:
-
GET /api (provides an in depth list of endpoint information)
https://nc-news-acw.onrender.com/api/
-
GET /api/topics (provides a list of article topics with a description & slug tag)
https://nc-news-acw.onrender.com/api/topics
-
GET /api/articles (provides all articles associated with the api)
https://nc-news-acw.onrender.com/api/articles
-
GET /api/articles?topic= (provides all articles associated with the given topic)
https://nc-news-acw.onrender.com/api/articles?topic=coding
-
GET /api/articles?sort_by= (provides all articles associated with the apo sorted by the given query)
https://nc-news-acw.onrender.com/api/articles?sort_by=author
-
GET /api/articles?sort_by=&order_by= (provides all articles associated with the apo sorted by the given query & ordered by another query)
https://nc-news-acw.onrender.com/api/articles?sort_by=author&order_by=asc
-
GET /api/articles/:article_id (provides a specific article by article_id)
https://nc-news-acw.onrender.com/api/articles/3
-
GET /api/articles/:article_id/comments (provides comments for the article_id provided)
https://nc-news-acw.onrender.com/api/articles/3/comments
-
GET /api/users (provides the username, name & avatar url for all users)
https://nc-news-acw.onrender.com/api/users
-
GET /api/articles?p= (provides the pagination for article listings)
https://nc-news-acw.onrender.com/api/articles?p=1
-
GET /api/articles/:article_id/comments?p= (provides the pagination for comments listings on single article pages)
https://nc-news-acw.onrender.com/api/articles/:article_id/comments?p=1
-
POST /api/articles/:article_id/comments (posts a comment on the associated article)
https://nc-news-acw.onrender.com/api/articles/3/comments
-
POST /api/users/signup (allows the user to sign up to the site - sign up is required to vote & comment)
https://nc-news-acw.onrender.com/api/users/signup
-
POST /api/users/login (allows the user to login to the site)
https://nc-news-acw.onrender.com/api/users/login
-
POST /api/articles (allows the user to add articles to the site)
https://nc-news-acw.onrender.com/api/articles
-
POST /api/topics (allows the user to add topics to the site)
https://nc-news-acw.onrender.com/api/topics
-
PATCH /api/articles/:article_id (updates the given article & returns it)
https://nc-news-acw.onrender.com/api/articles/3
-
DELETE /api/articles/:article_id (delete the associated article)
https://nc-news-acw.onrender.com/api/articles/3
-
DELETE /api/comments/:comment_id (deletes the associated comment)
https://nc-news-acw.onrender.com/api/comments/3
-
Clone the repository by copying the latest https link & typing the below command:
git clone https://github.com/AliCW/AliCW-be-NC-news.git
-
Please create .env.development (& if required .env.test) files in the root of the repo so as to connect to the database. The file should contain the below information:
PGDATABASE=nc_news
PGDATABASE=nc_news_test
-
The api was written using node.js version 19.0.0 & psql version 14.5. Installing these distributions or later (if available) is advised
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install 19
apt install postgresql
-
Install the npm package dependencies by running the below command in the root of the repo:
npm install
-
You will need to populate the psql database with information by typing the below command in the root of the repo:
npm run seed
-
To run testing functionality, you can run the below command in the repo root to run all the tests in tests/
npm run test
-
If you want to run a specific test file, navigate into tests/ and specify the file in question, e.g:
cd __tests__/ && npm test api-endpoints.test.js
Following the shutdown of https://www.elephantsql.com/ - postgresql data is hosted on https://supabase.com/