www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - vibe-d REST API: POSTing a struct

reply bomat <Tempest_spam gmx.de> writes:
Hey everyone,

I'm looking into vibe-d, particularly how to build a REST API 
server.
Given this struct:
```
struct Project
{
     string project_id;
     string name;
}
```
I could write a GETter like this:
```
 path("projects/:project_id")
Project getProject(string _project_id);
```
and a POST could look like this:
```
Project postProjects(string project_id, string name);
```

So far so good, this works.
What I don't like about the POST, though, is that I have to 
repeat `struct Project`'s members in the parameter list. This is 
redundant and will be inconvenient every time the struct changes, 
especially on ones with many members.

What I would prefer to have is something like this:
```
Project postProjects(Project project);
```
This is possible, the problem is that the POST request body now 
must look like this
```
{
project: {
         "project_id": "dummy_id",
         "name": "dummy"
     }
}
```
rather than simply this
```
{
     "project_id": "dummy_id",
     "name": "dummy"
}
```

So my question is, is it possible to have vibe-d parse the 
request body into a struct "implicitly"?

I hope the explanation was understandable. :)
Any help would be much appreciated.

Cheers,
bomat
Dec 01 2023
parent reply bomat <Tempest_spam gmx.de> writes:
On Friday, 1 December 2023 at 19:18:19 UTC, bomat wrote:
 So my question is, is it possible to have vibe-d parse the 
 request body into a struct "implicitly"?
I'm gonna answer my own question here, it's ` bodyParam`. https://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/40001/ https://github.com/vibe-d/vibe.d/pull/1676 I wasn't aware of the dedicated vibe-d forum before. As I've seen some vibe-d related questions in this forum as well, I thought this would be the place to ask...
Dec 02 2023
parent reply aj_dlang <joshiamit295 gmail.com> writes:
On Saturday, 2 December 2023 at 12:39:01 UTC, bomat wrote:
 On Friday, 1 December 2023 at 19:18:19 UTC, bomat wrote:
 So my question is, is it possible to have vibe-d parse the 
 request body into a struct "implicitly"?
I'm gonna answer my own question here, it's ` bodyParam`. https://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/40001/ https://github.com/vibe-d/vibe.d/pull/1676 I wasn't aware of the dedicated vibe-d forum before. As I've seen some vibe-d related questions in this forum as well, I thought this would be the place to ask...
does it active?
Dec 14 2023
parent bomat <Tempest_spam gmx.de> writes:
On Friday, 15 December 2023 at 07:36:04 UTC, aj_dlang wrote:
 does it active?
If you mean if that vibe-d forum is still active, I don't know. I tried to register, but I never got a confirmation mail... so probably not. On the other hand, there wasn't a response to my question on this board either, so don't really know what's the best place to get vibe-d support...
Dec 17 2023