# README
JSON-CRUD-API
A simple RESTful API built with Go, Gin, and GORM for creating, reading, updating, and deleting JSON data.
Features
- Create: Allows creating new posts.
POST /posts
- Read: Retrieves a list of posts or a single post by ID.
GET /posts
,GET /posts/:id
- Update: Updates an existing post by ID.
PUT /posts/:id
- Delete: Deletes a post by ID.
DELETE /posts/:id
Technologies Used
- Go: The programming language.
- Gin: A web framework for Go.
- GORM: An Object-Relational Mapper (ORM) for Go.
- PostgreSQL: (Assumed) The database used (Adapt if using a different database).
Setup
- Install Go: Ensure you have Go installed on your system. https://go.dev/doc/install
- Clone the repository:
git clone https://github.com/Francismensah/JSON-CRUD-API.git
- Install dependencies:
go mod tidy
- Set up environment variables: Create a
.env
file in the root directory and set theDB_URL
environment variable with your PostgreSQL connection string. Example:DB_URL="postgres://user:password@host:port/database?sslmode=disable"
- Run migrations: Run the
main.go
file to create the database tables and start the server. This also runs the migrations.go run main.go
API Endpoints
- POST
/posts
: Creates a new post. Request body should be a JSON object withtitle
andbody
fields. - GET
/posts
: Retrieves a list of all posts. - GET
/posts/:id
: Retrieves a single post by ID. - PUT
/posts/:id
: Updates an existing post. Request body should be a JSON object withtitle
andbody
fields. - DELETE
/posts/:id
: Deletes a post by ID.
Future Enhancements
- Add error handling and input validation.
- Improve API documentation.
- Implement authentication and authorization.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author