NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: Niels Larsen on May 02, 2025, 02:00:10 AM

Title: NetWebServiceMethod as REST - HOW?
Post by: Niels Larsen on May 02, 2025, 02:00:10 AM
Hi

I have a swagger that describes how to create my endpoint.
But I can't quite figure out how to receive values ​​as REST, for example like this:

http://127.0.0.1/WasteInvoice/InvoiceOverview/account/{accountId}/customer/{customerId}

Both variables are marked as "ID parameter for REST"

Regards Niels
Title: Re: NetWebServiceMethod as REST - HOW?
Post by: Jane on May 03, 2025, 12:03:39 PM
You can do a REST API without relying on a single REST ID to call it, Niels.

There are plenty of REST APIs I call with multiple parameters, such as
api.whatever.com/v2/appointments/booked?showpatientdetail=false&patientid=1&showcancelled=true&providerid=162
Title: Re: NetWebServiceMethod as REST - HOW?
Post by: Niels Larsen on May 04, 2025, 12:52:15 PM
Hi Jane

My challenge is that I have to follow the customer's guidelines and
they describe that I have to construct my methods with this syntax.
What you describe I am familiar with and have used in many projects.

Thanks for the input!!
Title: Re: NetWebServiceMethod as REST - HOW?
Post by: Jane on May 04, 2025, 03:51:07 PM
Are you making an API client or API server?
Can you post the exact spec of what you're trying to do?
Title: Re: NetWebServiceMethod as REST - HOW?
Post by: Niels Larsen on May 04, 2025, 09:17:38 PM
I am the one who makes the server but based on the customer's guidelines.
It's basically quite simple. I need to receive two parameters "accountId" and "customerId".
Normally I do it like this: 127.0.0.1//WasteInvoice/InvoiceOverview?account=12345&customer=6789
But the customer wants it like this:
http://127.0.0.1/WasteInvoice/InvoiceOverview/account/{accountId}/customer/{customerId}

Does that make sense?
Title: Re: NetWebServiceMethod as REST - HOW?
Post by: Bruce on May 04, 2025, 09:50:26 PM
>> But the customer wants it like this:
http://127.0.0.1/WasteInvoice/InvoiceOverview/account/{accountId}/customer/{customerId}

Have you told him how much extra that pattern will cost? I find that putting a price on it lets you determine how much they "actually want it".

>> Does that make sense?

yes.
To do this though you will need to parse the WholeURL yourself, likely in webHandler, setting the values as you interpret them (ie with a call to SetValue).
It's not terribly hard to do, but obviously is a custom approach to both parsing the values, and then redirecting the request to the correct API.

For example, in this URL I presume WasteInvoice is the name of the NetWebService, and InvoiceOverview is the name of the NetWebSericeMethod.
You *may* find it parses that sufficiently to get the call into the NetWebServiceMethod procedure, or you may need to parse it in webHandler.
Once you are in the method, you can then parse the URL further to find the account and customer ID. That's pretty easy to do with StringTheory etc.

Cheers
Bruce
Title: Re: NetWebServiceMethod as REST - HOW?
Post by: Niels Larsen on May 04, 2025, 10:20:59 PM
Thanks Bruce

That's pretty easy. I just took p_web.UserURL and fixed the rest with StringTheory.
Just glad I didn't miss a template option.

/Niels