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 2 - Capire's Hello World! (July Developer Challenge - "Reverse APIs")

qmacro
Developer Advocate
Developer Advocate
5,200

This is a task in the July Developer Challenge - "Reverse APIs".

This task is to add a second API endpoint to the service you already created in Task 1 - Your first service and first endpoint. It's nice and simple, and in fact is rather similar to the "Hello World!" example in Capire's "Getting Started" section ("Capire" is the friendly name for the CAP documentation). After you've completed this task, why don't you head over there and take a look around, as documentation goes, it's really rather awesome.

A second API endpoint in the "basic" service

To complete this task successfully, all you have to do is implement another API endpoint and make it available in the service you created in the previous task, and of course submit it to be tested by the TESTER. That means adding that API endpoint definition to the service definition in your CDS model, and then writing the implementation for it.

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 hello and be requestable via an HTTP GET method.

It should have a single parameter, to, and should return a String value, in the context of a JSON payload that looks like this:

{
  "@odata.context": "$metadata#Edm.String",
  "value": "Hello <value-of-argument-passed-to-the-to-parameter>!"
}
All this means is that you should declare and implement this API endpoint as an unbound function in the context of your existing service that is being served with the (default) OData V4 protocol.

🚨 Finally, be aware that the service should be served at the path /basic, and NOT at the path that's default for OData V4 services (which would be prefixed with /odata/v4). This was actually a requirement in the previous task - Task 1, but the TESTER was deliberately set to "lenient" mode for your very first API endpoint task. That "leniency mode" has been turned off now 🙂 So you may find yourself having to adjust your service so that it's served specifically at the /basic path. You may find the cds.serve() - @path section useful here.

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"/>
      </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>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>
You can see that this metadata document contains definitions for two FunctionImports "ping" and "hello".

Once you've got your service defined, and a simple implementation ready with an on handler for the hello 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 a value for the to parameter:

curl -s --url "localhost:4004/basic/hello(to='Zaphod')"
and the reponse should look like this:
{"@odata.context":"$metadata#Edm.String","value":"Hello Zaphod!"}

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-hello.

You'll have already done this sort of thing in the previous task 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-hello"
}
Note that the TESTER will pick a value for the to parameter, of course, and send it in the test call to your API endpoint.

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!

33 REPLIES 33

nidhi_m
Product and Topic Expert
Product and Topic Expert
5,156

Completed previous tasks as well. Pass! 

nidhi_m_1-1720517218865.png

nidhi_m_0-1720517117818.png

 

qmacro
Developer Advocate
Developer Advocate
0 Kudos
5,148

Speedy!

ajmaradiaga
Developer Advocate
Developer Advocate
5,138

¡Hola Capire! Or maybe I should say Ciao Capire!

ajmaradiaga_0-1720517858842.png

 

geek
Participant
5,066

@qmacro Sorry to be picky, given how helpful you were on Task 1 but the statement of requirement was

It should have a single parameter, to, and should return a String value, in the context of a JSON payload that looks like this:
{
  "@odata.context": "$metadata#Edm.String",
  "value": "Hello, <value-of-argument-passed-to-the-to-parameter>!"
}

N.B. The comma. However the model answer says:


With your server running (on, let's say, the default local CAP server port of 4004), make a request like this, supplying a value for the to parameter:
curl -s --url "localhost:4004/basic/hello(to='Zaphod')"
and the reponse should look like this:
{"@odata.context":"$metadata#Edm.String","value":"Hello Zaphod!"}

N.B. No comma.

Either way:

geek_0-1720522095845.pnggeek_1-1720522691396.png

 

qmacro
Developer Advocate
Developer Advocate
0 Kudos
4,917

Hey @geek ! Picky is good! And you gain extra kudos for being as sharp-eyed as this! You're right. Mea culpa, mea maxima culpa! 

To those future readers (who will be reading this thread after I've fixed what @geek has pointed out), the problem was there was a comma in the first example of what was required ("Hello, <value-of-argument-passed-to-the-to-parameter>!") but not in the second example ("Hello Zaphod!").

AndrewBarnard
Contributor
5,063

{"@odata.context":"$metadata#Edm.String","value":"PASS"}

@qmacro how are the TestLog results sorted?
Doesn't matter, this does what I want:
 https://developer-challenge-2024-07.cfapps.eu10.hana.ondemand.com/tester/Testlog?$orderby=createdAt%... 

 

0 Kudos
4,921

Yep, you found the intent of my simple (lazy) design - use the 'managed' common aspect to enhance an otherwise very simple `Testlog` entity, to give us some sensible data (e.g. `createdAt`) that is auto-added, and eminently sortable and filterable. 

Ruthiel
Product and Topic Expert
Product and Topic Expert
5,008

Hello @qmacro ,

Success!!!

Ruthiel_1-1720525622287.png

 

 

cguttikonda24
Participant
4,983

Hello DJ @qmacro 

{
ID: "4e51f802-24f1-438c-bc38-36a907d792b1",
task: "basic-hello",
result: "PASS",
createdAt: "2024-07-09T11:51:49.400Z",
createdBy: "Chanakya",
modifiedAt: "2024-07-09T11:51:49.400Z",
modifiedBy: "Chanakya",
serviceurl: "https://devchallenge-tasks.cfapps.us10-001.hana.ondemand.com/basic",
communityid: "cguttikonda24"
}

 

mwn
Participant
4,960

For those who want to use a Windows command line, here's what I successfully used:

curl ^
  --data "{""communityid"":""mwn"",""serviceurl"":""https://mn.cfapps.us10-001.hana.ondemand.com/basic"",""task"":""basic-hello""}" ^
  --header "Content-Type: application/json" ^
  --url "https://developer-challenge-2024-07.cfapps.eu10.hana.ondemand.com/tester/testServer"

qmacro
Developer Advocate
Developer Advocate
0 Kudos
4,930

Thanks @mwn I for one appreciate that! 😉 

 

qmacro_2-1720530915513.png

 

 

mxmw
Explorer
4,782

PASS! 🙂

mxmw_0-1720535117478.png

 

M-K
Active Participant
4,629

Here's my submission:

MK_0-1720542490065.png

Thanks to @MioYasutake for giving me the idea how to POST and GET to the tester service via http-file

MK_1-1720542937315.png

 

qmacro
Developer Advocate
Developer Advocate
0 Kudos
4,133

Awesome to see folks working with / learning from each other.

Alpesa1990
Participant
4,565

My submission for task 2.

Alpesa1990_0-1720548863402.png

 

eshrinivasan
Developer Advocate
Developer Advocate
4,521

Submission for task 2

eshrinivasan_0-1720551004876.png

 

MioYasutake
Active Contributor
4,444

My submission for week 2. 

MioYasutake_0-1720555159476.png

 

sudarshan_b
Participant
4,367

Finally got it working 🙂  It took me quite a while to realise that my test was failing because I missed the exclamation mark (!) in the result...       "Hello Capirates!" 😄

sudarshan_b_2-1720558114184.png

 

qmacro
Developer Advocate
Developer Advocate
0 Kudos
4,126

Nice test string, btw ("Capirates") 😉

BTW, I was meaning to ask you (as I noticed it in your response to a previous task) - do you use the `-k` curl option (to disable cert checks) deliberately? I'm curious, why do you do that (I'm thinking that I can learn something here, hence my question)?

4,052

Hi DJ,

Yes I used '-k' deliberately to bypass the certificate authentication issue (corporate laptop + docker container 😉 ) For some reasons I am getting certificate issues in my docker container, maybe I need to update the CA certificate my container. Hoping that fixes it! 

0 Kudos
3,151

My submission for task 1&2

Cmdd_0-1721053152024.png

 

gphadnis2000
Participant
4,205

Reverse api task 2 submission

gphadnis2000_0-1720594903623.png

 

krishnan-jr
Explorer
3,987

Done!!

krishnanjr_0-1720631478100.png

 

spassaro
Participant
3,946

PASS!!!😅

spassaro_0-1720639512612.png

 

YogSSohanee
Participant
3,922

Hello @qmacro ,

PFB the response from the Task 2 api endpoint - 

YogSSohanee_0-1720645498313.png

And following is the response from the tester :

YogSSohanee_1-1720645537482.png

 

 

tobiasz_h
Active Participant
3,751

Hello,

tobiasz_h_0-1720682315836.png

 

vineelaallamnen
Explorer
3,609

task2 

vineelaallamnen_0-1720743984448.png

 

ManojKumarVarma
Explorer
3,370

Hello,

please find the submission

ManojKumarVarma_0-1720772569881.pngManojKumarVarma_1-1720772574505.png

ManojKumarVarma_2-1720772577700.png

Thanks,

Manoj Kumar Potharaju.

MatLakaemper
Participant
3,188

my result.

MatLakaemper_0-1720960645085.png

 

emiliocampo
Explorer
2,859

My Task2 Submission

emiliocampo_0-1721555113616.pngemiliocampo_1-1721555205996.png

 

Liyon_SV
Explorer
2,800

Hello World 😀

Liyon_SV_1-1721708859121.png

 

 

brahammittal
Explorer
0 Kudos
2,651

brahammittal_0-1722500890543.png

 

brahammittal_1-1722500906642.png

 

harsh_itaverma
Participant
2,635

Pass 🙂

harsh_itaverma_0-1722541350753.pngharsh_itaverma_1-1722541389348.png