Marketplace is a Spring Boot based project with a RESTful API service for placing bids and offers within a marketplace.
This is a standard Gradle project, so just run ./gradlew build test
and the project will be compiled and the tests will run.
You require the following to build the project:
JDK 8 is required to build and run this project.
The project uses Spring Boot which makes configuring and running a web based application a breeze.
In order to run the project from the command line do the following:
From the project base directory you can run ./gradlew bootRun
which will start the application on http://localhost:8080
The project is configured with three RESTful API operations:
- Register Bid
- Register Offer
- Retrieve Bids
- Retrieve Offers
- Retrieve Orders
- Retrieve Current Bid Price
- Retrieve Current Offer Price
When called, this API operation will register a bid in the system. Registering a bid may result in one or more orders being generated and the bid being removed from the marketplace.
$ curl -v -X POST -H "Content-Type: application/json" -d '{"quantity": 1,"userId": 2,"pricePerUnit": 19900, "itemId":12345}' http://localhost:8080/marketplace/bids
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> POST /marketplace/bids HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 65
>
* upload completely sent off: 65 out of 65 bytes
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Length: 0
< Date: Wed, 27 Jul 2016 12:13:27 GMT
<
* Connection #0 to host localhost left intact
### Register Offer
When called, this API operation will register an offer in the system. Registering an offer may result in one or more orders being generated and the offer being removed from the marketplace.
$ curl -v -X POST -H "Content-Type: application/json" -d '{"quantity": 1,"userId": 3,"pricePerUnit": 900, "itemId":999}' http://localhost:8080/marketplace/offers
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> POST /marketplace/offers HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 63
>
* upload completely sent off: 63 out of 63 bytes
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Length: 0
< Date: Wed, 27 Jul 2016 12:15:41 GMT
<
* Connection #0 to host localhost left intact
When called, this API operation will return all registered bids for the given user.
$ curl -v http://localhost:8080/marketplace/bids?userId=2
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /marketplace/bids?userId=2 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Wed, 27 Jul 2016 12:18:16 GMT
<
* Connection #0 to host localhost left intact
[{"id":1,"itemId":12345,"userId":2,"quantity":1,"pricePerUnit":19900,"dateCreated":1469621607889}]
When called, this API operation will return all registered offers for the given user.
$ curl -v http://localhost:8080/marketplace/offers?userId=3
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /marketplace/offers?userId=3 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Wed, 27 Jul 2016 12:17:14 GMT
<
* Connection #0 to host localhost left intact
[{"id":1,"itemId":999,"userId":3,"quantity":1,"pricePerUnit":900,"dateCreated":1469621729993}]
When called, this API operation will return all orders for the given user. If the buyer is supplied, returns all the orders relating to the supplied buyer. If the buyer is omitted and the seller is supplied, the operation will return all orders relating to the supplied seller. If neither is true, an exception is thrown.
The example below returns all orders for the given buyer.
$ curl -v http://localhost:8080/marketplace/orders?buyerId=2
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /marketplace/orders?buyerId=2 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Wed, 27 Jul 2016 12:20:00 GMT
<
* Connection #0 to host localhost left intact
[{"id":1,"itemId":12345,"buyerId":2,"sellerId":3,"quantity":1,"pricePerUnit":19900}]
The example below returns all orders for the given seller.
$ curl -v http://localhost:8080/marketplace/orders?sellerId=3
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /marketplace/orders?sellerId=3 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Wed, 27 Jul 2016 12:20:20 GMT
<
* Connection #0 to host localhost left intact
[{"id":1,"itemId":12345,"buyerId":2,"sellerId":3,"quantity":1,"pricePerUnit":19900}]
When called, this API operation will return the highest price of all bids for the given item.
curl -v http://localhost:8080/marketplace/bids/12345/currentPrice
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /marketplace/bids/12345/currentPrice HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Wed, 27 Jul 2016 12:14:38 GMT
<
* Connection #0 to host localhost left intact
19900
When called, this API operation will return the lowest price of all offers for the given item.
curl -v http://localhost:8080/marketplace/offers/999/currentPrice
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /marketplace/offers/999/currentPrice HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Wed, 27 Jul 2016 12:16:20 GMT
<
* Connection #0 to host localhost left intact
900