Skip to content

Yarden-zamir/palindromeRestApi

Repository files navigation

Logo

A REST API that manages messages and preforms basic checks/operations on them

Report a Bug · Request a Feature . Ask a Question

MIT Kotlin style checks issues kotlin carrots

Architecture doodle

image

The server is built in a way that is independent from palindrome checking, instead palindrome checking is added via a mini dsl like so

fun Application.module() {
    //app logic here
    configureLogicFields { //add any function you would like to evaluate as logic field
        add(::palindrome)
    }
}

Then we query v1/messages/{id}/logicfields/palindrome we get the output of said function on the given message (in this case true or false).
Adding additional logic is as simple as referencing a function

fun Application.module() {
    //app logic here
    configureLogicFields { //add any function you would like to evaluate as logic field
        add(::palindrome)
        add(::messageSize)
    }
}
fun messageSize(message: Message): String {
    return message.text.length.toString()
}

Now v1/messages/{id}/logicfields/messagesize will give us the length of the message's text content

Get started

Run the server

After cloning, use gradle run to run the project locally
By default the project will use an embedded database when launched, so you don't need to have anything else setup. If you do have a database, please define environment variables db=true and JDBC_DATABASE_URL={your database url}
example environment

    db=true;JDBC_DATABASE_URL=jdbc:postgresql:messages?user=postgres&password=palindrome

The tests are all under gradle test
When committing, the tests will also run on the cloud and if they pass the code will be deployed on heroku

Use the live server

You can visit and query the API at palindrome-rest-api.herokuapp.com

Use demo client

You can download the client from https://github.com/PandaBoy444/palindromeClient/releases, it is recommended to use a terminal that supports colors like the Windows Terminal

API reference

Action Method Endpoint Arguments
Create message POST v1/messages text={Text for new message}
Delete message DELETE v1/messages/{id}
Update message PATCH v1/messages/{id} text={New text for message}
Replace (or create) message PUT v1/messages/{id} text={Text for new message}
Retrieve all messages GET v1/messages
Retrieve message GET v1/messages/{id}
Retrieve field from message GET v1/messages/{id}/{field}
Retrieve logic fields from message GET v1/messages/{id}/logicfields
Retrieve logic field from message GET v1/messages/{id}/logicfields/{field}
Check if a message is palindrome GET v1/messages/{id}/logicfields/palindrome

Status code reference

Status code
200 OK Found message/s Updated message
201 Created Message created
204 No Content Message deleted
400 Bad Request Parameter missing Illegal ID
404 Not Found Didn't find message with ID Didn't find field/logic field with name
418 I'm a teapot Refused to brew coffee

Dependencies

Targeting jvm 1.8

Dependency Version Job
Kotlin 1.6.10 Language and friend
Ktor 1.6.8 Server framework
Logback 1.2.5 Logging
Exposed 0.17.14 Database abstraction and type safety
postgresql 42.3.3 Database
embedded-postgres 1.3.1 Embedded database for testing and no database environments

About

An application that manages messages and preforms basic checks on them

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published