Skip to content

girisagar46/casspring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

casspring

A dead simple REST API using spring boot.

Setup

Run postgres instance in Docker

docker run --name postgres-spring -e POSTGRES_PASSWORD=password -d -p 5432:5432 postgres:alpine

Your docker container port will be exposed to port 5432. To verify, docker port postgres-spring

Go inside the postgres container

$ docker exec -it $(docker ps -aqf "name=postgres-spring") bash

Create database inside the Postgres container

bash-5.0# psql -U postgres
postgres=# CREATE DATABASE casspring; 

How to run

  1. Package with maven

    $ mvn package
  2. Run the jar file

    $ java -jar target/casspring-0.0.1-SNAPSHOT.jar
  3. Application runs at port 8080

API Endpoints

  1. GET

    $ curl -XGET localhost:8080/api/v1/person
      [{"id":"43ce8819-9ac2-4575-9903-ffc0872cd1f2","name":"Ms. Bar"},{"id":"72dde85b-ca22-4966-9aa8-9c9fa6e17ca3","name":"James Bond 123"}]
  2. GET one item

    $ curl -XGET localhost:8080/api/v1/person/43ce8819-9ac2-4575-9903-ffc0872cd1f2
        {"id":"43ce8819-9ac2-4575-9903-ffc0872cd1f2","name":"Ms. Bar"}
  3. POST

    $ curl --location --request POST 'localhost:8080/api/v1/person' --header 'Content-Type: application/json' --data-raw '{ "name": "James Bond 007" }'
  4. DELETE

    $ curl --location --request DELETE 'localhost:8080/api/v1/person/466767ca-151b-4d9d-a749-659904d02415'
  5. PUT

    $ curl --location --request PUT 'localhost:8080/api/v1/person/72dde85b-ca22-4966-9aa8-9c9fa6e17ca3' --header 'Content-Type: application/json' --data-raw '{ "name": "James Bond 456" }'