Alura Challenge: Forum-Hub. Java BackEnd API REST
This API REST system simulates the functionality of a Forum using four main endpoints. It supports the GET, POST, PUT and DELETE http methods.
- Every endpoint capable of returning an object response, it will return the status code and a json.
- The system uses PostgresSQL for the database.
- The url before the endpoints can be adjusted according to the needs. (e.g.,
http:/anyserver/ENDPOINT
). - The system has four main endpoints: /login, /topic, /author and /answer. Each one of them correspond to different aspects and will vary on the http methods allowed.
-
The only http method it accepts is POST.
-
This endpoint does not require any kind of authorization, so anyone can access to it.
-
You need to send a Json with valid credentials in order to recive a JsonWebToken that will allow you to access all the other endpoints.
-
Example of the Json with credentials:
-
If your credentials are valid you will recive your JWT and it will valid for two hours according to the UTC(-06:00).
-
Once you have recived your JWT, you will be able to access all the other endpoints.
-
This endpoint will accept GET, POST, PUT and DELETE http methods.
-
Only the active topics will be considered for this functions (
status = true
). -
-
To register a new topic, you need to send a Json which can't have empty information.
-
Example of a valid Json:
-
If the request is successful you will get a 201 status code, the created object and its location
http:/server/topic/TOPIC_ID
): -
If you try to register a topic with the same
title
andmessage
that another topic, you will get a 400 status code.
-
-
-
Endpoint("/all"):
-
Endpoint("/firstTen"):
- This endpoint will return a list of ten topics in ascending order according to their
creation_date
.
- This endpoint will return a list of ten topics in ascending order according to their
-
Endpoint("/title/{title}"):
-
Endpoint("/author/{id}"):
-
Endpoint("/course/{id}"):
-
Endpoint("/{id}"):
-
-
- Endpoint("/{id}"):
-
This endpoint allowes you to update a topic by its id.
-
Example of a valid Json to update a topic:
-
You can omit any of the Json properties as this is only an update.
-
If the topic is found and the Json is valid, you will recive a Json of the updated object:
-
If the topic is not found, you will get a 404 status code.
-
- Endpoint("/{id}"):
-
- Endpoint("/{id}"):
- This endpoint allowes you to delete a topic by its id.
- If the topic is found, you will only get a 200 status code.
- If the topic is not found, you will get a 404 status code.
- Endpoint("/{id}"):
-
This endpoint will accept GET and PUT http methods.
-
-
Endpoint("/{id}"):
-
Endpoint("/name/{name}"):
-
Endpoint("/email/{email}"):
-
-
- Endpoint("/{id}"):
-
This endpoint allowes you to update an author by its id.
-
Example of a valid Json to update an author:
-
You can omit any of the Json properties as this is only an update.
-
If the author is found and the Json is valid, you will revice a Json of the updated object:
-
If the author is not found, you will get a 404 status code.
-
- Endpoint("/{id}"):
- This endpoint will accept GET, POST, PUT and DELETE http methods.
-
- Endpoint("/add"):
-
This endpoint allowes you to add a new answer.
-
You need to send a Json which can't have empty information.
-
Example of a valid Json:
-
If the request is successful you will get a 201 status code, the created object and its location
http:/server/answer/ANSWER_ID
: -
If your request is missing something or it is not correct, you will get a 400 status code.
-
- Endpoint("/add"):
-
- Endpoint("/{id}"):
-
This endpoint allowes you to update an answer by its id.
-
Example of a valid Json to update an answer:
-
You can omit any of the Json properties as this is only an update.
-
If the answer is found and the Json is valid, you will revice a Json of the updated object:
-
If the answer is not found, you will get a 404 status code.
-
- Endpoint("/{id}"):
-
- Endpoint("/{id}"):
- This endpoint allowes you to delete an answer by its id.
- If the answer is found, you will only get a 200 status code.
- If the answer is not found, you will get a 404 status code.
- Endpoint("/{id}"):
- The API uses JWT (JSON Web Token) for authentication and authorization.
- The token must be included in the
Authorization
header for all requests except the/login
endpoint. - Ensure secure storage of tokens on the client side.