Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Task 3 - Multi-parameter basic sum function (July Developer Challenge - "Reverse APIs")

qmacro
Developer Advocate
Developer Advocate
3,393

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>
}
All this means is that you should declare and implement this API endpoint as another unbound function

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>
You can see that this metadata document contains definitions for this new FunctionImport "sum", as well as the two previous FunctionImports "ping" and "hello".

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)"
and the reponse should look like this:
{"@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"
}
And, just as with the previous (and all further tasks):
  • 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!

24 REPLIES 24

mxmw
Explorer
3,107

Nice one again!

mxmw_0-1720684187256.png

 

nidhi_m
Product and Topic Expert
Product and Topic Expert
3,095

Done!

nidhi_m_1-1720684630694.png

 

sudarshan_b
Participant
3,019

Task 3 submission, PASS 

sudarshan_b_0-1720691393673.png

P.S.: Hi DJ, the certificate issue is resolved now, so no more '-k' 😉

qmacro
Developer Advocate
Developer Advocate
0 Kudos
2,924

Nice!

mwn
Participant

qmacro
Developer Advocate
Developer Advocate
0 Kudos
2,661

Very nice! I was wondering if folks would do something with the Testlog entity set data 🙂 Good work!

0 Kudos
2,227

Thanks for the kudo!

I've now removed the need to get the results in a separate browser tab. I've also given an option to remove qmacro's results(!) and you can optionally enter your communityid, which will highlight that row in the results table.

michaelnicholls.github.io/results.html

geek
Participant

spassaro
Participant

Alpesa1990
Participant
2,745

My submission for task 3.

Alpesa1990_0-1720713852346.png

 

eshrinivasan
Developer Advocate
Developer Advocate
2,662

Submission for task 3

eshrinivasan_0-1720716726679.png

 

MioYasutake
Active Contributor
2,570

My submission for task 3.

MioYasutake_0-1720727781059.png

 

gphadnis2000
Participant
2,428

My submission for task 3

gphadnis2000_0-1720765037306.png

 

YogSSohanee
Participant
2,381

Hi @qmacro ,

PFB my response for task 3:

unbound function sum response 

YogSSohanee_0-1720768008088.png

Updated Metadata document:

YogSSohanee_1-1720768060148.png

 

And ofcourse the tester response

YogSSohanee_0-1720768474089.png

 

 

tobiasz_h
Active Participant
2,362

Hello,

tobiasz_h_0-1720769526303.png

 

Ruthiel
Product and Topic Expert
Product and Topic Expert
2,318

Hello!!
Success again!

Ruthiel_0-1720774572882.png

 

vineelaallamnen
Explorer

MatLakaemper
Participant
1,840

my result sum

MatLakaemper_0-1720960762277.png

 

M-K
Participant
1,816

Here's my submission:

MK_0-1720982287354.png

 

Cmdd
Participant
1,682

Task 3 submission

Cmdd_1-1721118776263.png

 

 

emiliocampo
Explorer
1,173

My Task3 Submission

emiliocampo_0-1721555972041.png

emiliocampo_1-1721555992994.png

 

Liyon_SV
Explorer
1,063

Done 🙂

Liyon_SV_1-1721708957804.png

 

 

brahammittal
Explorer

harsh_itaverma
Participant
906

Pass 🙂

harsh_itaverma_0-1722542939852.png

 

harsh_itaverma_1-1722542957897.png