REST API for querying and retrieving scoped news and information within an organization
Ben Ruwel
This is a REST API that is used to post news, view information of departments and its employees(users). It has features that allows one access specific info about users and departments, view a list of all the users in a department and also the list of departments a user is associated with.
This is program is wholely written in Java and built with
- Oracle Java 11.8
- Gradle 6.5
- Spark 2.7.2
- Postgres 42.2.5
- Gson 2.8.6
- Apache Maven 2.3.2
- Heroku Plugin 3.0.2
- JUnit4
To get a local copy up and running follow these simple example steps.
In order to build this app locally, first make sure you have all the programs listed in Built with. Some can be added as dependencies, please check with the build tool you wish to use.o
-
Clone the repo
$ git clone https://github.com/benruwel/OrgNewsPortal.git
-
If you don't have Postgres installed on your local PC visit this to install it
-
Enable gradle to import all the dependencies automatically
This api is hosted on Heroku, so you can choose to consume using this link https://org-news-portal.herokuapp.com/
These are the REST api routes:
Behavior | Path | Http Verb |
---|---|---|
Create a new departmetnt | /department/new | POST |
Delete a specific department | /department/:department_id | DELETE |
View info a specific department | /department/:departmetn_id | GET |
Get a list of all departments | /departments | GET |
Create a new user/employee | /users/new | POST |
Get a list of users | /users | GET |
Post news about a specific department | /departments/:department_id/news/new | POST |
Get a list of the news relating to specific department | /departments/:department_id/news | GET |
Add a user to a department | departments/:department_id/user/:user_id/new | POST |
View a list of the employees/users in a department | /departments/:department_id/users | GET |
View list of departments an employee is associated with | /user/:user_id/departments | GET |
You may also choose to build this project locally and consume the api with the localhost port with the following steps:
-
Open your preferred terminal
-
You will need to create the databases with a specific schema, navigate to src/main/resources/DB and run this command
$ psql > create.sql
This creates org_news_portal (developmetn db) and org_news_portal_test (test db) on your local machine
If in any instance you will require to delete the databases, run this:
$ psql > drop.sql
-
Then to run the project, navigate to your project's root directory run the project with
$ gradle run
-
Open postman and use the
localhost:4567
URL to test the endpoints stipulated above.
This project uses Gson to change Java objects to JSON format, which is the golden standard for most apis.
POST method behavior:
- User fires a POST method e.g. POST department/new, though the data may differ according to the given body object, there will be a similar 201 response with the generated Json object.
{ "name": "HR", "id": 2, "description": "Comfortable workspaces to thrive in", "number_of_employees": 2 }
GET method behavior
- User fires a GET method e.g. GET /departments, in this case, the response will be a Json object with an array of all the departments.
[ { "name": "Software Dev", "id": 1, "description": "Hot Java all day, both coffee and code", "number_of_employees": 10 }, { "name": "HR", "id": 2, "description": "Comfortable workspaces to thrive in", "number_of_employees": 2 } ]
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- 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
Distributed under the MIT License. See LICENSE
for more information.
My email - ruwelmwangi@gmail.com