This project contains the api for Mrtechspecs website, where users can find the latest specifications about the latest phones.
You will need:
You will need:
- Spring Data JPA
- MySQL Connector
- Spring WEB
- JUnit
- JUnit Vintage Engine
- Spring Boot Test Starter
- Spring Boot Maven Plugin
First, clone the project:
$ git clone https://github.com/ealili/springboot-rest-api.git
Second, configure the database.
- Create a MySQL database using the
mrtech.sql
script provided in the root folder. - Add credentials to
/src/main/resources/application.properties
.
The default ones are:
spring.datasource.url=jdbc:mysql://localhost:3306/mrtech
spring.datasource.username=root
spring.datasource.password=
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.hibernate.ddl-auto = update
Finally, open the project using your favorite IDE and install all the listed dependencies above and you should be able to run the project.
If everything works, you should see an Index Page here.
Index Page, later this endpoint will provide all the available routes.
- URL
http://localhost:8080/
, METHOD = GET.
- URL
http://localhost:8080/api/administrator
, METHOD = POST, expects JSON body.
e.g. Getting an administrator at (http://localhost:8080/api/administrator) using the JSON objet below:
{
"username": "selaudin",
"password": "selaudin123"
}
At this point there is no authentication provided for the administrator.
- URL
http://localhost:8080/api/administrator/save
, METHOD = POST, expects JSON body.
e.g. Saving an administrator at (http://localhost:8080/api/administrator/save) using the JSON object below:
{
"username": "agni",
"name": "Agni Ramadani",
"password": "agni123"
}
- URL
http://localhost:8080/api/administrator/update/{username}
, METHOD = POST, expects a path variableusername
and a JSON body.
e.g. Updating an administrator at (http://localhost:8080/api/administrator/update/selaudin) using the JSON object below:
{
"username": "sela",
"name": "Selaudin",
"password": "sela123"
With this object the username
which is a primary key in the administrator table will also get updated.
- URL
http://localhost:8080/api/administrator/delete/{username}
, METHOD = GET, expects a path variableusername
.
e.g. Deleting an administrator with the username selaudin
at (http://localhost:8080/api/administrator/delete/selaudin)
- URL
http://localhost:8080/api/phones
, METHOD = GET.
- URL
http://localhost:8080/api/phones/{mname}
, METHOD = GET, expects a path variablemname
.
e.g. Getting phones of the manufacturer called Samsung
at (http://localhost:8080/api/phones/Samsung)
- URL
http://localhost:8080/api/phone/{id}
, METHOD = GET, expects a path variableid
.
e.g. Getting a phone with the id samsungGalaxyNote10
at (http://localhost:8080/api/phone/samsungGalaxyNote10)
- URL
http://localhost:8080/api/phone/save
, METHOD = POST, expects a JSON body.
eg Saving a phone at (http://localhost:8080/api/phone/save) using the JSON body below:
{
"displayType": "Super AMOLED capacitive touchscreen, 16M colors",
"displayResolution": "1080 x 2400 pixels",
"displaySize": "6.5 inches",
"selfieCamera": "32 MP, f/2.2",
"mainCamera": "48 MP, f/2.0, 12 MP, f/2.2, 5 MP, f/2.4, 5 MP, f/2.2",
"mname": "Samsung",
"name": "Samsung Galaxy A51",
"productionYear": "2019",
"technology": "GSM / HSPA / LTE",
"weight": "172 g (6.07 oz)",
"sound": "Single Speaker",
"os": "Android 9 (One UI)",
"battery": "Non-removable Li-ion 4000 mAh battery",
"imgSource": "https://fdn2.gsmarena.com/vv/pics/samsung/samsung-galaxy-a51-sm-a515-1.jpg"
}
- URL
http://localhost:8080/api/phone/update/{id}
, METHOD = POST, expects a path variableid
and a JSON body.
e.g. Updating a phone at (http://localhost:8080/api/phone/update/samsungGalaxyA9) using
{
"displayType": "Super AMOLED capacitive touchscreen, 16M colors",
"displayResolution": "1080 x 2400 pixels",
"displaySize": "6.5 inches",
"selfieCamera": "32 MP, f/2.2",
"mainCamera": "48 MP, f/2.0, 12 MP, f/2.2, 5 MP, f/2.4, 5 MP, f/2.2",
"mname": "Samsung",
"name": "Samsung Galaxy A10",
"productionYear": "2019",
"technology": "GSM / HSPA / LTE",
"weight": "172 g (6.07 oz)",
"sound": "Single Speaker",
"os": "Android 9 (One UI)",
"battery": "Non-removable Li-ion 4000 mAh battery",
"imgSource": "https://fdn2.gsmarena.com/vv/pics/samsung/samsung-galaxy-a51-sm-a515-1.jpg"
}
As we see here the phone with the id samsungGalaxyA9
will be updated with the JSON body provided above. The id will change due to its name
- URL
http://localhost:8080/api/phone/delete/{id}
, METHOD = GET, expects a path variableid
.
e.g. Deleting a phone with the id samsungGalaxyNote10
at (http://localhost:8080/api/phone/delete/samsungGalaxyNote10)
- URL
http://locahost:8080/api/manufacturers
, METHOD = GET.
- URL
http://localhost:8080/api/manufacturer/save
, METHOD = POST, expects a JSON body.
e.g. Saving a manufacturer at (https://localhost:8080/api/manufacturer/save) using the JSON object below:
{
"mname": "OnePlus,
"headquarters": "China"
}
- URL
http://localhost:8080/api/manufacturer/delete/{mname}
, METHOD = GET, expects a path variablemname
.
e.g. Deleting a manufacturer with the name Samsung
(http://localhost:8080/api/manufacturer/delete/Samsung)