{"id":27455564,"url":"https://github.com/capella-marcosfilipe/marcoscapella-blog-api-java","last_synced_at":"2026-04-10T23:46:10.291Z","repository":{"id":287408118,"uuid":"962268114","full_name":"capella-marcosfilipe/marcoscapella-blog-api-java","owner":"capella-marcosfilipe","description":"REST API for marcoscapella blog made in Java Spring","archived":false,"fork":false,"pushed_at":"2025-04-11T14:32:02.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T16:51:13.968Z","etag":null,"topics":["java","postgresql","rest-api","spring-boot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/capella-marcosfilipe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-07T22:48:05.000Z","updated_at":"2025-04-11T14:32:05.000Z","dependencies_parsed_at":"2025-04-11T15:48:19.645Z","dependency_job_id":"75d844ca-857a-465a-b8da-98350c13d5db","html_url":"https://github.com/capella-marcosfilipe/marcoscapella-blog-api-java","commit_stats":null,"previous_names":["capella-marcosfilipe/marcoscapella-blog-api-java"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/capella-marcosfilipe/marcoscapella-blog-api-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capella-marcosfilipe%2Fmarcoscapella-blog-api-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capella-marcosfilipe%2Fmarcoscapella-blog-api-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capella-marcosfilipe%2Fmarcoscapella-blog-api-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capella-marcosfilipe%2Fmarcoscapella-blog-api-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/capella-marcosfilipe","download_url":"https://codeload.github.com/capella-marcosfilipe/marcoscapella-blog-api-java/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capella-marcosfilipe%2Fmarcoscapella-blog-api-java/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259606974,"owners_count":22883559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","postgresql","rest-api","spring-boot"],"created_at":"2025-04-15T16:44:06.229Z","updated_at":"2026-04-10T23:46:10.259Z","avatar_url":"https://github.com/capella-marcosfilipe.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📝 A Java REST API for a Simple Personal Blog\n\nThis is the backend for a simple blog application, built with **Spring Boot**. It exposes a RESTful API that handles blog posts, tags, and authors. The frontend is built using **Angular** and communicates with this API.\n\n---\n\n## 🚀 Features\n\n- Create, read, update, and delete blog posts\n- Associate posts with multiple tags (many-to-many relationship)\n- Link posts to authors (many-to-one relationship)\n- Generate slugs automatically from post titles\n- Automatically create and associate tags on post creation\n- Securely expose selected user information in responses\n- Ready for deployment on [Render](https://render.com)\n\n---\n\n## 🛠️ Tech Stack\n\n- Java 17+\n- Spring Boot 3+\n- Spring Data JPA\n- PostgreSQL\n- Angular (Frontend)\n- Maven\n\n---\n\n## 📦 Endpoints Overview\n\n### 📝 Posts\n\n| Method | Endpoint             | Description                          |\n|--------|----------------------|--------------------------------------|\n| GET    | `/posts`             | Get all posts                        |\n| GET    | `/posts/{id}`        | Get a post by ID                     |\n| GET    | `/posts/slug/{slug}` | Get a post by slug                   |\n| POST   | `/posts`             | Create a new post                    |\n| PUT    | `/posts`             | Update a post                        |\n| PATCH  | `/posts/{id}`        | Update a post partially\n| DELETE | `/posts/{id}`        | Delete a post by ID                  |\n\n---\n\n### 🏷️ Tags\n\n| Method | Endpoint           | Description                          |\n|--------|--------------------|--------------------------------------|\n| GET    | `/tags`            | Get all tags                         |\n| GET    | `/tags/{name}`     | Get a tag by name                    |\n| POST   | `/tags`            | Create a new tag                     |\n| DELETE | `/tags/{id}`       | Delete a tag by ID                   |\n\n---\n\n### 👤 Users\n\n| Method | Endpoint                     | Description                          |\n|--------|------------------------------|--------------------------------------|\n| GET    | `/users`                     | Get all users                        |\n| GET    | `/users/{id}`                | Get user by ID                       |\n| GET    | `/users/email/{email}`       | Get user by email                    |\n| GET    | `/users/username/{username}` | Get user by username                 |\n| POST   | `/users`                     | Create a new user                    |\n| PUT    | `/users/{id}`                | Update a user                        |\n| DELETE | `/users/{id}`                | Delete a user                        |\n\n---\n\n### ❤️ Health Check\n\n| Method | Endpoint     | Description            |\n|--------|--------------|------------------------|\n| GET    | `/health`    | Returns `OK` if running|\n\n---\n\n## 📤 Request/Response Format\n\nRequest/Response format uses DTOs for better control and separation of concerns.\n\n### Sample JSON (POST `/api/posts`)\n\n```json\n{\n  \"title\": \"Building a Career You Love\",\n  \"content\": \"It takes time, effort, and alignment...\",\n  \"published\": true,\n  \"author\": { \"id\": 1 },\n  \"tags\": [\n    { \"id\": 1 },\n    { \"id\": 2 }\n  ]\n}\n\n```\n\n---\n\n## 🧪 Running Locally\n\n### Prerequisites\n\n- Java 17+\n- Maven\n- PostgreSQL running locally or via Docker\n\n### 1. Clone the project\n\n### 2. Configure environment variables\n\nIn `src/main/resources/application.properties`, reference your hidden environment variables like this:\n\n```properties\nspring.datasource.url=${DB_URL}\nspring.datasource.username=${DB_USER}\nspring.datasource.password=${DB_PASS}\n```\n\nOn **Render**, you can set these variables securely in the dashboard.\n\nFor local development, you can use a `.env` file with tools like [dotenv-spring](https://github.com/cdimascio/dotenv-java) or export them manually:\n\n```bash\nexport DB_URL=jdbc:postgresql://localhost:5432/blogdb\nexport DB_USER=your_user\nexport DB_PASS=your_password\n```\n\n### 3. Run the app\n\n```bash\n./mvnw spring-boot:run\n```\n\nServer will start at `http://localhost:8080`.\n\n---\n\n## 🌐 CORS Configuration\n\nCORS is enabled in `WebConfig.java` to allow requests from your Angular frontend:\n\n```java\n.allowedOrigins(\"http://localhost:4200\")\n```\n\nMake sure to update it for production.\n\n---\n\n## ⚙️ JPA Notes\n- Some endpoints use `JOIN FETCH` queries to avoid `LazyInitializationException`.\n- Relationships like Post -\u003e Tags are lazily loaded by default for performance.\n- `@Transactional` annotations may be used in service methods to control session scope.\n\n---\n\n## 📦 Deployment on Render\n\n- Create a PostgreSQL instance\n- Add environment variables in the Render dashboard:\n    - `DB_URL`\n    - `DB_USER`\n    - `DB_PASS`\n- Deploy as a Java service using:\n    - Build Command: `./mvnw clean package`\n    - Start Command: `java -jar target/*.jar`\n\n---\n\n## ✍️ Author\n\nDeveloped by [**Marcos Capella**](https://marcoscapella.com.br) \nFeel free to connect: [LinkedIn](https://linkedin.com/in/marcoscapella)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapella-marcosfilipe%2Fmarcoscapella-blog-api-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcapella-marcosfilipe%2Fmarcoscapella-blog-api-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapella-marcosfilipe%2Fmarcoscapella-blog-api-java/lists"}