-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This server is based on Spring Boot which allows users to create easy stand-alone, production-grade Spring based Applications. This server is using the following methods depending on which endpoint you are sending your request.
GET
POST
DELETE
All of the features that is explained below are also implemented in the front-end of the server where you can see, create and delete posts.
The main endpoint of this server is http://localhost:8080/
or http://localhost:8080/index.html
. When a client sends a GET
request to these endpoint the response will be the html code of the main page which can be opened in the browser. But if client sends a POST
or any other http method to this endpoint the server will return a 405 Method Not Allowed
response in json format.
{ "timestamp": "2021-12-20T00:01:39.625+00:00", "status": 405, "error": "Method Not Allowed", "trace": "org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported....", "message": "Request method 'POST' not supported", "path": "/" }
The blog endpoint of this server is at http://localhost:8080/blog
and this endpoint supports the GET
, POST
and DELETE
methods. The example and explanation of each method is described below.
This method will return a json response will all blog posts available.
curl -XGET 'http://localhost:8080'
The response of will be an array of blog posts:
[ { "id": "bf94aca0-14a6-4e21-b9ac-bcaabb38224b", "title": "Code block", "content": "This aspncfsiadnmad
asdkas pdas mdkaspkdpsad,sapd,as", "date": "2021-12-20" } ]
This method will make a new blog post in the database. The body of the POST
method should be defined in a json format with the following structure:
{ "title": "Title of the blog", "content": "Content of the blog which accepts html elements." }
Example:
curl -XPOST -d '{ "title": "Blog 1231", "content": "THIS IS THE CONTENT" }' 'http://localhost:8080/blog'
If the results where successfull the server will return nothing. In addition, if there is a blog with the exact title, the server will return an 500 Internal Server
error to prevent posts with exact title.
This method is used to delete a blog post. The endpoint for this method is defined as: http://localhost:8080/blog/id
where, id
is refering to the blog's id which can be found in the blog endpoint. Example:
curl -XDELETE 'http://localhost:8080/blog/d378be8c-8d41-4769-afac-342b2d7c1a92'
If the delete operation was successful the server will return nothing otherwise it will return an error.