Test SAP CAP OData Services with curl

When developing a CAP service, testing the OData endpoint independently helps separate service logic from front-end problems. Start with a local development instance and an entity exposed by your service.

Read records

curl -i 'http://localhost:4004/odata/v4/catalog/Books'

Replace the service and entity names with those defined in your CDS model. Inspect the HTTP status and JSON response.

Test writes in development

curl -i -X POST 'http://localhost:4004/odata/v4/catalog/Books' -H 'Content-Type: application/json' -d '{"ID":42,"title":"Demo"}'

This creates a record if the entity permits creation and the payload matches its model. Use PATCH with the correct OData key predicate to test updates. For secured endpoints, use the appropriate authentication and avoid putting credentials into shell history. In BAS, a REST Client .http file offers another way to send development requests.

SAP Note: 3698709

You May Also Like

Leave a Reply?