Keywords: Java backend
, NoSQL (Neo4j)
, REST API
, Maven
This is an Java implementation of the backend for a service that allows users to post, view and delete blog posts. Dependency injection was done through Dagger. REST-api was used for server communication.
- The backend is running on port 8080.
- MongoDB database is called as
blogs
; - Collections called
posts
;
- Command Line:
- Install maven
- To compile your code simply run mvn compile in the root directory (the folder that has pom.xml)
- To run your code run mvn exec:java
- Eclipse:
- File → Import → Maven → Existing Maven Projects
- Navigate to the project location
- Right click the project → Maven Build…
- Input compile exec:java in the Goals input box
- Click apply then run/close
- You can now run the project by pressing the green play button
- Intellij:
- Import project
- Navigate to the project location
- Import project from external model → Maven
- Next → Next → Next → Finish
- Add Configuration → + Button → Maven
- Name the configuration and input
exec:java
in the Command Line box - Apply → Ok
- You can now run the project by pressing the green play button
-
Response Body:
- JSON format
-
Response Status:
- 200 OK for successful delete
- 400 BAD REQUEST if the request body is improperly formatted or missing required information
- 500 INTERNAL SERVER ERROR if save or add was unsuccessful (if user has done everything as per requirements but request is unable to respond correctly)
- 404 NOT FOUND if post does not exist
- 405 METHOD NOT ALLOWED if called with something other than GET, PUT, DELETE
-
Existing endpoints:
- (GET) http://localhost:8080/api/v1/post
- Get blog post. Returns list of corresponding posts. If _id is specified, return the exact post that has that _id. If title is specified, return all posts that contain the specified words in the given title, in order.
- Request Body:
{
"title": "First"
}
or
{
"_id": "3m4jk393jneke93h3k"
}
or
{
"title": "First"
"_id": "3m4jk393jneke93h3k"
}
- (PUT) http://localhost:8080/api/v1/post
- Request Body:
{
"title": "My First Post",
"author": "Jake Peralta",
"content": "This is my first post. I’m very excited to create this blog. YAY!",
"tags": [
"first post",
"new blog",
"excitement"
]
}
- Request Body:
- (DELETE) http://localhost:8080/api/v1/post
- Request Body:
{
"_id": "3m4jk393jneke93h3k"
}
- Request Body:
- (GET) http://localhost:8080/api/v1/post
-
PostMan Testing Package: You can download it from the PostMan folder.