Step 6: Run (Part 2)
Run Your Local Web Server
Open a terminal window.
Enter Your Client Credentials
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.
Export your registered client credentials (see the Prerequisites) as environment variables.
Identity Provider (the IDP with whom you registered your application):
read -s MY_SOLID_IDP && export MY_SOLID_IDP
Enter https://login.inrupt.com
Client ID:
read -s MY_SOLID_CLIENT_ID && export MY_SOLID_CLIENT_ID
Enter your Client ID.
Client Secret:
read -s MY_SOLID_CLIENT_SECRET && export MY_SOLID_CLIENT_SECRET
Enter your Client Secret.
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
.
Test the Service
Open another terminal window. To test, call the new endpoints defined in the ExpenseController
class:
/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/"]
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"
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 Module.
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"
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 Module.
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"] }'
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 Module.
Last updated