This is a task in the July Developer Challenge – “Reverse APIs”.
This task is to add a final API endpoint to the service you already created in Task 1 – Your first service and first endpoint. It expands a little on the previous task to cement the idea of parameter definitions and access to them in the implementation.
The requirements
Here are the specific requirements for this task.
The API endpoint should be made available within the existing service basic. Relative to the service path, the name should be sum and be requestable via an HTTP GET method.
It should be defined with two Integer parameters, a and b, and should return an Integer value, being the sum of a and b, in the context of a JSON payload that looks like this (pretty-printed for readability here):
{ "@odata.context": "$metadata#Edm.Int32", "value": <sum-of-a-and-b> }
When this API endpoint is added to the service and served via the OData V4 protocol, the service metadata document should look like this:
<?xml version="1.0" encoding="utf-8"?> <edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"> <edmx:Reference Uri="https://sap.github.io/odata-vocabularies/vocabularies/Common.xml"> <edmx:Include Alias="Common" Namespace="com.sap.vocabularies.Common.v1"/> </edmx:Reference> <edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.xml"> <edmx:Include Alias="Core" Namespace="Org.OData.Core.V1"/> </edmx:Reference> <edmx:DataServices> <Schema Namespace="basic" xmlns="http://docs.oasis-open.org/odata/ns/edm"> <EntityContainer Name="EntityContainer"> <FunctionImport Name="ping" Function="basic.ping"/> <FunctionImport Name="hello" Function="basic.hello"/> <FunctionImport Name="sum" Function="basic.sum"/> </EntityContainer> <Function Name="ping" IsBound="false" IsComposable="false"> <ReturnType Type="Edm.String"/> </Function> <Function Name="hello" IsBound="false" IsComposable="false"> <Parameter Name="to" Type="Edm.String"/> <ReturnType Type="Edm.String"/> </Function> <Function Name="sum" IsBound="false" IsComposable="false"> <Parameter Name="a" Type="Edm.Int32"/> <Parameter Name="b" Type="Edm.Int32"/> <ReturnType Type="Edm.Int32"/> </Function> </Schema> </edmx:DataServices> </edmx:Edmx>
Once you’ve got your service defined, and a simple implementation ready with an on handler for the sum event, you’re ready.
It is definitely worth testing it yourself first, e.g. with curl, Postman, or even the REST Client extension to VS Code that some of you are using (going on what I can see from some of your responses to the previous task). Use whatever tool you prefer for making HTTP calls.
With your server running (on, let’s say, the default local CAP server port of 4004), make a request like this, supplying values for the a and b parameters:
curl -s --url "localhost:4004/basic/sum(a=100,b=50)"
{"@odata.context":"$metadata#Edm.Int32","value":150}
Submitting your API endpoint to the TESTER
Now you’re ready to submit your CANDIDATE service, with the specific API endpoint, to the TESTER!
The payload
The task identifier you need to supply in the payload of your submission is: basic-sum.
You’ll have already done this sort of thing previously so just head back there for the more detailed instructions if you need them, or to the the section titled “The Tester service, and making a test request” in the main challenge blog post.
Now, to have your freshly minted API endpoint in this task tested, you’ll need to submit a JSON payload like this:
{ "communityid": "<your-community-id>", "serviceurl": "<the-URL-of-your-service>", "task": "basic-sum" }
-
the value for the communityid property should be your ID on this SAP Community platform (e.g. mine is “qmacro”)
-
the value for the serviceurl property should be the absolute URL (i.e. including the scheme), of your CANDIDATE service which contains the API endpoint (see ℹ️ A note on URLs and services), not the full URL of the specific API endpoint itself
That’s it!
Logging of test results
Remember that you can check on your progress, and the progress of your fellow participants – all requests are logged and are available in an entity set served by the TESTER service. The entity set URL is https://developer-challenge-2024-07.cfapps.eu10.hana.ondemand.com/tester/Testlog and being an OData V4 entity set, all the normal OData system query options are available to you for digging into that information.
Until the next task, have fun, and if you have any questions or comments, leave them below!