Skip to content

A simple RESTful API for managing messages and determining if they are palindromes

Notifications You must be signed in to change notification settings

Shawn1912/messages-service

Repository files navigation

Messages Service

Description

A simple Go-based microservice that provides CRUD operations for messages and includes palindrome detection functionality.

Architecture

Test Image 4

Project Structure

messages-service/
├── database
   ├── db_connection_test.go
   ├── db_connection.go
   ├── models.go
   └── schema.sql
├── handlers
   ├── handlers.go
   └── handlers_test.go
├── utils
   ├── palindrome.go
   └── palindrome_test.go
├── go.mod
├── go.sum
├── main.go
└── main_test.go

Build and Run

Prerequisites

  • Go (version 1.17 or higher)
  • Docker
  • PostgreSQL

Steps

  1. Clone the repository

    git clone https://github.com/shawn1912/messages-service.git
    cd messages-service
  2. Set up the database

    Ensure PostgreSQL is running and create the messages database.

    psql -U postgres
    CREATE DATABASE messages;
    \q

    Run the schema script:

    psql -U postgres -d messages -f ./database/schema.sql
  3. Run the application

    go run .

API Endpoints

  • POST /message: Create a new message.
  • GET /messages: List messages (max 100).
  • GET /message/{id}: Retrieve a message.
  • PUT /message/{id}: Update a message.
  • DELETE /message/{id}: Delete a message.

Example: Creating a message

curl -X POST http://localhost:8080/messages \
  -H 'Content-Type: application/json' \
  -d '{"content": "A man a plan a canal Panama"}'

Response

{
  "id": 29,
  "content": "A man a plan a canal Panama",
  "isPalindrome": true,
  "createdAt": "2024-10-28T12:00:00Z",
  "updatedAt": "2024-10-28T12:00:00Z"
}

Testing

Run unit tests:

go test ./...

About

A simple RESTful API for managing messages and determining if they are palindromes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published