Giter VIP home page Giter VIP logo

java-spring-rest-app's Introduction

java-spring-rest-app

Prerequisites:

  • mysql
  • java 8
  • Spring Boot 2.6.6
  • maven
  1. Install mysql:

apt-get install mysql-server

  1. Create the database

sudo mysql --password

mysql> create database db_example; -- Creates the new database mysql> create user 'springuser'@'%' identified by 'ThePassword'; mysql> grant all on db_example.* to 'springuser'@'%';

  1. Build app

./mvnw clean package

  1. RUN SPRING APP

java -jar target/entex-0.0.1-SNAPSHOT.jar test-java-fullstack-county.csv test-java-fullstack-locality.csv

The jar file receives 2 arguments: first the county csv file, then the locality csv file.

  1. Populate the database

Make a rest call to populate the database.

curl -X GET http://localhost:8080/demo/populate_database

This may take a couple of minutes.

select count() from locality; should return 13733 entries select count() from county; 42 entries

  1. Login

Get token

curl -X POST http://localhost:8080/demo/login -d username=administrator -d password=password

If username is 'administrator' and password is 'password' a token will be generated for further requests.

  1. Get all users

curl -X GET http://localhost:8080/demo/user -H "token: 25213761-0a10-4e2d-bb48-b0818d835df5"

[{"name":"Cornel","email":"[email protected]","password":"password","countyName":"Bucuresti","localityName":"Bucuresti","userId":18},{"name":"Ion","email":"[email protected]","password":"password","countyName":"Suceava","localityName":"Suceava","userId":21},{"name":"Ana","email":"[email protected]","password":"password","countyName":"Suceava","localityName":"Suceava","userId":22},{"name":"Cornel","email":"[email protected]","password":"password2","countyName":"Bucuresti","localityName":"Bucuresti","userId":25},{"name":"Cornel","email":"[email protected]","password":"password2","countyName":"Suceava","localityName":"Suceava","userId":27},{"name":"Maria","email":"[email protected]","password":"parola","countyName":"Dolj","localityName":"Craiova","userId":28}]

  1. Get all users with a specific name

curl -X GET http://localhost:8080/demo/user?name=Maria -H "token: 25213761-0a10-4e2d-bb48-b0818d835df5"

[{"name":"Maria","email":"[email protected]","password":"parola","countyName":"Dolj","localityName":"Craiova","userId":28}]

  1. Create user

curl -X POST http://localhost:8080/demo/user -H "token: 25213761-0a10-4e2d-bb48-b0818d835df5" -d name=Marius -d email=[email protected] -d password=password -d locality_name=Craiova

{"name":"Marius","email":"[email protected]","password":"password","countyName":"Dolj","localityName":"Craiova","userId":31}

  1. Edit user (for example email)

curl -X PUT http://localhost:8080/demo/user -H "token: 25213761-0a10-4e2d-bb48-b0818d835df5" -d id=31 -d email=[email protected]

{"name":"Marius","email":"[email protected]","password":"password","countyName":"Dolj","localityName":"Craiova","userId":31}

  1. Delete User

curl -X DELETE http://localhost:8080/demo/user -H "token: 25213761-0a10-4e2d-bb48-b0818d835df5" -d id=25

Deletion was succesfull.

  1. Open Browser to see the user table

http://localhost:8080/demo/user/details

java-spring-rest-app's People

Contributors

cradulux avatar cornelradu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.