Skip to content
Aaron Hanusa edited this page Aug 19, 2016 · 23 revisions

Application Walkthrough

The sample application is a ficticious order entry / inventory management system web api.

This walkthrough will cover creating a customer, category, product, and placing an order on behalf of the new customer via the api. Further, you will ship an order and see how it affects inventory as well. Along the way, you will see the peasy-js validation rules engine in action and how you can use concurrency techniques within your middle tier.

In order to successfully follow along with this tutorial, please be sure to read [running the application] (https://github.com/peasy/peasy-js-samples#running-the-application).

This tutorial uses Postman to interact with the web api, however, you can choose to use whatever http communication tool that you are comfortable with.

Customers

To begin, let's query our current users:

You should notice that one customer is returned and that a status code of 200 is returned.

Let's create a new customer who we will eventually place an order on behalf of:

Notice that a POST request was made with the content type set as application/json. Further, notice that the request resulted with a status code of 201. Make note of the customer id that was assigned.

Categories

Now let's query for existing categories:

You should notice that one category is returned and that a status code of 200 is returned.

Let's create a new category:

Notice that a POST request was made with the content type set as application/json. Further, notice that the request resulted with a status code of 201. Make note of the category id that was assigned.

Products

Now let's query for existing products:

You should notice that two categories are returned and that a status code of 200 is returned.

Let's create a new product and intentionally post an empty request body:

Notice that the response code is 400 and that we receive an array containing errors about the required values that were not supplied. These validation rules are wired up in the CreateProductCommand exposed via the ProductService. You can learn more about business services here and more about commands here.

Also notice that the returned error objects contain association and message values. The association field is particularly helpful for UI consumption scenarios.

Now let's attempt to create a new product, supplying all of the required information:

Notice that a POST request was made with the content type set as application/json. Further, notice that the request resulted with a status code of 201. Make note of the product id that was assigned.

Inventory Items

Now let's query for existing inventory items:

You should notice that inventory items are returned and that a status code of 200 is returned.

Make special note of the inventory item with the product id of 3. This inventory item was created on our behalf when we created the "Javascript: the good parts" product.

Orders

Now let's create a new order on behalf of our new customer:

Notice that a POST request was made with the content type set as application/json. Further, notice that the request resulted with a status code of 201. Make note of the order id that was assigned.

Now let's add an order item specifying our new product (Javascript: the good parts) to the order:

Notice that a POST request was made with the content type set as application/json. The OrderItemService has been wired up with business rules associated with the insert that ensures that the order item's amount == the product price * quantity. Therefore, because we specified an amount of 51, we received a 400 status code and a validation error in our response payload.

Let's correct our mistake and attempt to create the order item again:

Notice that the request resulted with a status code of 201. Make note of the order item id that was assigned.

Clone this wiki locally