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. You can learn 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.

Clone this wiki locally