CRUD Operation using Action in CAP

In this example, Our goal is to create Employee Schema and perform CRUD Operation to it.

We will be following below steps-

      1. Creating a CAP App.
      2. Create Schema in db and Add Data.
      3. Create Service cds file and declare the endpoints.
      4. Create Service js file and define the endpoint logic.
      5. Deploy the db Data on SqLite.
      6. Run the app and Test it using HTTP File.

Step 1 - Creating a CAP App

Use the below command to create a CAP Application -

Now, go inside the Project Folder, and install the dependencies. -

Step 2 - Create Schema in db and Add Data

In the db Folder create Schema.cds file

In the Schema.cds use below code to create Entity -

To add data we needs to create csv files, hence run the below command -

Now in data folder inside db folder paste the below data -

Step 3 - Create Service cds file and declare the endpoints

Create service.cds file inside srv folder -

Step 4 - Create Service js file and define the endpoint logic

Create service.js file inside srv folder -

Step 5 - Deploy the db Data on SqLite

For Local Testing, deploy the data into SqLite server using below command -

Step 6 - Run the app and Test it using HTTP File

In your app create Test Folder and create test.http file inside it.

Now run your app using cds watch and test these APIs on test.http file.

And it is done, You can deploy your app and use it. !!!