NetTalk Central

Author Topic: NetWebServiceMethod as REST - HOW?  (Read 3709 times)

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
    • Email
NetWebServiceMethod as REST - HOW?
« 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

Jane

  • Sr. Member
  • ****
  • Posts: 399
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: NetWebServiceMethod as REST - HOW?
« Reply #1 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

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
    • Email
Re: NetWebServiceMethod as REST - HOW?
« Reply #2 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!!

Jane

  • Sr. Member
  • ****
  • Posts: 399
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: NetWebServiceMethod as REST - HOW?
« Reply #3 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?

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
    • Email
Re: NetWebServiceMethod as REST - HOW?
« Reply #4 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?

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11310
    • View Profile
Re: NetWebServiceMethod as REST - HOW?
« Reply #5 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

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
    • Email
Re: NetWebServiceMethod as REST - HOW?
« Reply #6 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