Coder Social home page Coder Social logo

mateuspontess / blog-san-api Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 300 KB

Blog-san is a blog API, where users can create posts, comments and reply to comments.

License: MIT License

Java 100.00%
jwt-token rest-api spring-boot spring-security integration-testing test-containers unit-testing

blog-san-api's Introduction

โ˜๏ธ๐Ÿค“ About the project

Blog-san is a simple REST API project, with the intention of practicing, CRUD, mapping and entity relationships. There, users can create an account, publish, comment and respond.


โš™๏ธ Functionalities

๐ŸŸข User registration;

๐ŸŸข Authentication and authorization;

๐ŸŸข CRUD for publications and comments;

๐ŸŸข Public acces for readers, but without interactions with publications and other users;

๐ŸŸข Integrations between publications to comments and comments to comments;


๐Ÿ› ๏ธ Tecnologies

How to use

Run

  • Clone this repository
  • Run the command mvn spring-boot:run in the root directory or import the Maven project and run it in your IDE
  • Access the URL http://localhost:8080

Note

  • All GET request endpoints are accessible without authentication.

Register

  • To create posts and comments, you need to register:

POST: /auth/register
Content-Type: application/json

{
	"login": "newUser",
	"password": "newPassword",
	"name": "Example Name",
	"email": "[email protected]"
}

By default, all users are created with the USER role. To become an ADMIN, you need to change your role attribute in the database. There is an endpoint capable of creating users with the ADMIN role, but only users with the ADMIN role can access it.


Login

  • After registering, you need to authenticate:

POST: /auth/login
Content-Type: application/json

{
	"login": "root",
	"password": "root",
}

Response:

{
  "token": "your_access_token"
}

This access token will be your 'free pass' to create posts and comments


Using the access token

After receiveing the successful access token, you need to include the header for your future requests. The access token must be passed as parte of the "Authorization" title.

Header example:

Authorization: Bearer your_access_token

Publication creation

POST: /publications

{
  "description": "Publication content",
  "imageLink": "link_for_image"
}

Response:

{
    "publicationId": 1,
    "userId": 1,
    "nameUser": "Your User Name",
    "description": "Publication content",
    "imageLink": "link_for_image",
    "date": "2024-02-10 19:13"
}

Comment creation

POST: /publications/{publicationId/comments

{
	"publicationId": 1,
	"text": "Comment example"
}

Response:

{
    "commentId": 1,
    "userId": 1,
    "text": "Comment example",
    "date": "2024-02-10 19:10",
    "edited": false
}

These are basic examples, and you can explore other endpoints as needed. Be sure to replace the dummy values with actual data from your development environment.


Spring Doc

Postman

You can also import my set of requests into Postman. There you have all the endpoints with all the necessary URL parameters and body details to interact with the API.

Run In Postman

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.