{"id":31737489,"url":"https://github.com/chimake/blog-api","last_synced_at":"2025-10-09T09:22:44.421Z","repository":{"id":315663007,"uuid":"1060332508","full_name":"chimake/blog-api","owner":"chimake","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-19T22:02:57.000Z","size":83,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-20T00:48:15.375Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Blade","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chimake.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-19T18:26:26.000Z","updated_at":"2025-09-19T22:03:00.000Z","dependencies_parsed_at":"2025-09-20T00:48:17.052Z","dependency_job_id":"7c4eb0d5-a380-4c60-9072-804d81cf886e","html_url":"https://github.com/chimake/blog-api","commit_stats":null,"previous_names":["chimake/blog-api"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/chimake/blog-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chimake%2Fblog-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chimake%2Fblog-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chimake%2Fblog-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chimake%2Fblog-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chimake","download_url":"https://codeload.github.com/chimake/blog-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chimake%2Fblog-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001122,"owners_count":26083021,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-10-09T09:22:43.273Z","updated_at":"2025-10-09T09:22:44.415Z","avatar_url":"https://github.com/chimake.png","language":"Blade","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blog API - Mini Blog Assignment\n\nA complete REST API for a blog system built with PHP 8+ and Laravel, featuring JWT authentication, CRUD operations, search functionality, and comprehensive testing.\n\n## Features\n\n### Core Requirements\n-  **User Authentication** - JWT-based registration and login using Laravel Sanctum\n-  **Blog Post CRUD** - Create, read, update, delete posts with proper authorization\n-  **Public Access** - Anyone can view posts list and individual posts\n-  **Database Design** - Proper relationships between users and posts\n\n### Bonus Features\n-  **Search Functionality** - Filter posts by title or body content\n-  **Pagination** - 10 posts per page with metadata\n-  **Comprehensive Error Handling** - Try-catch blocks with proper HTTP status codes\n-  **Database Optimization** - Indexes for performance\n\n## Tech Stack\n\n- **Backend**: PHP 8.1+, Laravel 11\n- **Database**: MySQL\n- **Authentication**: Laravel Sanctum (JWT)\n- **Testing**: Postman Collection included\n\n## API Endpoints\n\n### Authentication\n| Method | Endpoint | Description | Auth Required |\n|--------|----------|-------------|---------------|\n| POST | `/api/register` | User registration | No |\n| POST | `/api/login` | User login | No |\n| POST | `/api/logout` | User logout | Yes |\n| GET | `/api/user` | Get current user | Yes |\n\n### Posts (Public)\n| Method | Endpoint | Description | Auth Required |\n|--------|----------|-------------|---------------|\n| GET | `/api/posts` | List all posts (paginated) | No |\n| GET | `/api/posts/{id}` | Get single post | No |\n| GET | `/api/posts/search?q=term` | Search posts | No |\n\n### Posts (Authenticated)\n| Method | Endpoint | Description | Auth Required |\n|--------|----------|-------------|---------------|\n| POST | `/api/posts` | Create new post | Yes |\n| PUT | `/api/posts/{id}` | Update own post | Yes |\n| DELETE | `/api/posts/{id}` | Delete own post | Yes |\n| GET | `/api/my-posts` | Get user's posts | Yes |\n\n##  Installation \u0026 Setup\n\n### Prerequisites\n- PHP 8.1 or higher\n- Composer\n- MySQL\n- Laravel CLI (optional)\n\n### Installation Steps\n\n1. **Clone the repository**\n```bash\ngit clone https://github.com/chimake/blog-api.git\ncd blog-api\n```\n\n2. **Install dependencies**\n```bash\ncomposer install\n```\n\n3. **Environment setup**\n```bash\ncp .env.example .env\nphp artisan key:generate\n```\n\n4. **Database configuration**\nUpdate your `.env` file:\n```env\nDB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=blog_api\nDB_USERNAME=your_username\nDB_PASSWORD=your_password\n```\n\n5. **Create database**\n```bash\nmysql -u your_username -p\nCREATE DATABASE blog_api;\nexit\n```\n\n6. **Run migrations**\n```bash\nphp artisan migrate\n```\n\n7. **Start the server**\n```bash\nphp artisan serve\n```\n\nThe API will be available at `http://localhost:8000`\n\n\n## Testing\n\n### Using Postman\n1. Import the `postman-collection.json` file\n2. Set up environment with `base_url = http://localhost:8000`\n3. Run the authentication flow first to get tokens\n4. Test all endpoints using the organized folder structure\n\n### Test Flow\n1. **Register** a new user → Token automatically saved\n2. **Create posts** → Post IDs saved for testing\n3. **Test public endpoints** → No authentication required\n4. **Test authenticated endpoints** → Uses saved tokens\n5. **Test error scenarios** → Validation and authorization\n\n\n## Authentication\n\nThe API uses **Laravel Sanctum** for JWT token-based authentication:\n\n1. Register or login to receive a token\n2. Include token in requests: `Authorization: Bearer YOUR_TOKEN`\n3. Tokens are required for creating, updating, deleting posts\n4. Users can only modify their own posts\n\n## Search \u0026 Pagination\n\n### Search\n```bash\nGET /api/posts/search?q=laravel\n```\n\n### Pagination\n```bash\nGET /api/posts?page=2\n```\n\nResponse includes pagination metadata:\n```json\n{\n  \"pagination\": {\n    \"current_page\": 1,\n    \"last_page\": 3,\n    \"per_page\": 10,\n    \"total\": 25,\n    \"from\": 1,\n    \"to\": 10\n  }\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchimake%2Fblog-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchimake%2Fblog-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchimake%2Fblog-api/lists"}