Step 6: Run (Part 2)#

Run Your Local Web Server#

Open a terminal window.

Enter Your Client Credentials#

  1. Export your registered client credentials (see the Prereqisites) as environment variables.

    Warning

    Safeguard your Client ID and Client Secret values. Do not share these with any third parties as anyone with your Client ID and Client Secret values can impersonate you and act fully on your behalf.

    1. Identity Provider (the IDP with whom you registered your application):

      read -s MY_SOLID_IDP && export MY_SOLID_IDP
      

      Enter https://login.inrupt.com

    2. Client ID:

      read -s MY_SOLID_CLIENT_ID && export MY_SOLID_CLIENT_ID
      

      Enter your Client ID.

    3. Client Secret:

      read -s MY_SOLID_CLIENT_SECRET && export MY_SOLID_CLIENT_SECRET
      

      Enter your Client Secret.

    4. Authentication Flow Method:

      read -s MY_AUTH_FLOW && export MY_AUTH_FLOW
      

      Enter client_secret_basic

Run the Application#

Once you have entered your client credentials, start your application. From your project (getting-started/) directory, run your Spring Boot application:

  • For Java, this tutorial assumes a Spring Boot Web Maven Project.

  • For Kotlin, this tutorial assumes a Spring Boot Web Gradle Project.

./mvnw spring-boot:run

Your Web service runs on http://localhost:8080.

Reminder

The application is running as you, the user who registered it.

Test the Service#

Open another terminal window. To test, call the new endpoints defined in the ExpenseController class:

Endpoint

Description

/api/expenses/receipts/add

Saves a non-RDF resource, namely an image file of a receipt, to a location in the Pod and updates the Expense object with the receipt location.

Returns the updated Expense object.

/api/resource/nonRDF/add

Saves a non-RDF resource to a location in the Pod.

Returns the identifier (as String) for the saved resource.

Get Pod URL#

To find your Pod URL, issue the following curl command, substituting your WebID (e.g., https://id.inrupt.com/yourUserName):

curl -X GET http://localhost:8080/api/pods\?webid\=SUBSTITUTE_YOUR_WEBID

Upon success, the operation should return an array with your Pod Root URL; for example:

["https://storage.inrupt.com/your-root-container/"]

Note

In the following operations, substitue your-root-container with the value of your root container.

Add a Receipt to Existing Expense#

To add a receipt to an existing expense created in Part 1, call the api/expenses/receipts/add endpoint with a local .png file (can be a different file type .jpg, .pdf, etc. as well), substituting the path to your local file and your root container in the request body:

curl -X PUT http://localhost:8080/api/expenses/receipts/add \
          -H "Content-Type: multipart/form-data" \
          -F "destinationURL=https://storage.inrupt.com/your-root-container/expenses/20230315/receipt.png" \
          -F "file=@/my/local/file/path/to/receipt.png" \
          -F "expenseURL=https://storage.inrupt.com/your-root-container/expenses/20230315/expense1"

Tip

  • If you encounter an HTTP 403 Forbidden error, double check that you have substituted your-root-container in the command.

  • If you encounter a PreconditionFailedException, check that the receipt.png does not already exist at the the specified identifier. The .create() operation errors with PreconditionFailedException if a resource already exists. See CRUD for details.

Upon success, the operation should return the updated Expense object as JSON (as well as print out, on the server-side, the content formatted in Turtle):

{
    "identifier": "https://storage.inrupt.com/your-root-container/expenses/20230315/expense1",
    "merchantProvider": "Example Restaurant",
    "expenseDate": "2023-03-15T00:00:00.000+00:00",
    "description": "Team Lunch",
    "amount": 100,
    "currency": "USD",
    "category": "Travel & Entertainment",
    "receipts": [
        "https://storage.inrupt.com/your-root-container/expenses/20230315/receipt.png"
    ],
    "rdftype": "https://schema.org/Invoice"
}

See also CRUD.

Save a Non-RDF File#

To save a receipt (a non-RDF resource) to your Pod, issue the following curl command to the api/resource/nonRDF/add endpoint, substituting the path to your local file and your root container in the request body:

curl -X PUT http://localhost:8080/api/resource/nonRDF/add \
          -H "Content-Type: multipart/form-data" \
          -F "destinationURL=https://storage.inrupt.com/your-root-container/expenses/20230327/receipt.png" \
          -F "file=@/my/local/file/path/to/newreceipt.png"

Tip

  • If you encounter an HTTP 403 Forbidden error, double check that you have substituted your-root-container in the command.

  • If you encounter a PreconditionFailedException, check that the resource does not already exist at the the specified identifier. The .create() operation errors with PreconditionFailedException if a resource already exists. See CRUD for details.

Upon success, the operation returns identifier (as string) of the resource:

https://storage.inrupt.com/your-root-container/expenses/20230327/receipt.png

See also CRUD.

Create an Expense Record#

Using the receipt saved in the Save a Non-RDF File section, create a new expense that includes the receipt info, substituting your root container in the request body:

curl -X POST http://localhost:8080/api/expenses/create \
   -H 'Content-type:application/json'  \
   -d '{
      "identifier": "https://storage.inrupt.com/your-root-container/expenses/20230327/expense1",
      "merchantProvider": "Example Supply Store",
      "description": "Chair",
      "expenseDate": "2023-03-27",
      "amount": 400,
      "currency": "USD",
      "category": "Office Equipment & Supplies",
      "receipts": [ "https://storage.inrupt.com/your-root-container/expenses/20230327/receipt.png"] }'

Tip

  • If you encounter an HTTP 403 Forbidden error, double check that you have substituted your-root-container in the command.

  • If you encounter a PreconditionFailedException, check that the resource does not already exist at the the specified identifier. The .create() operation errors with PreconditionFailedException if a resource already exists. See CRUD for details.

Upon success, the operation should return the updated Expense object as JSON (as well as print out, on the server-side, the content formatted in Turtle):

{
    "identifier": "https://storage.inrupt.com/your-root-container/expenses/20230327/expense1",
    "merchantProvider": "Example Supply Store",
    "expenseDate": "2023-03-27T00:00:00.000+00:00",
    "description": "Chair",
    "amount": 400,
    "currency": "USD",
    "category": "Office Equipment & Supplies",
    "receipts": [
        "https://storage.inrupt.com/your-root-container/expenses/20230327/receipt.png"
    ],
    "rdftype": "https://schema.org/Invoice"
}

See also CRUD.