vibe-d REST API: POSTing a struct
bomat
Tempest_spam at gmx.de
Fri Dec 1 19:18:19 UTC 2023
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
More information about the Digitalmars-d-learn
mailing list