Some basic newbie questions on server connect / api development

So, after a couple of days playing around with Wappler, I might jump on the train and start a real world project. So be prepared for a number of questions on the server- and frontend side.

Let’s start with the some where I couldn’t find answers in the docs or forum:

  1. How can I output variables and queries to the server console?
  2. I would like to use JSON to transfer data from the frontend to the API (there will be a website and mobile app). Would be “Object” the right type on $_POST? But how to access the data? Couldn’t find documention and unfortunatly no way to output the $_POST the the console.
  3. How to create my own response object as JSON?
  4. How to do simple server side logic (aka “Service Layer”), like comparing a number of fields values and do simple math based on this field values? Natively with Wappler or RunJS?

Cheers,
Heiko

Currently there’s no native Step to output variables to the server console. This can achieved by using console.log in RunJS. The standard practice within the Wappler community is to use Set Value and inspect the result in your browser’s developer tools network tab

$_POST is a valid object, yes. Generally, people use the dot syntax (e.g.: $_POST.name) to access a certain property inside such object

You can use Set Value with the Output checkbox ticked, and those that you want to hide just untick them. Alternatively, you can use the Group step with Set Values inside, and then use the Response step to return the Group step you’ve previously created

You can use the step Condition to perform comparisons, along with many of the built-in formatters (e.g.: .count()). For complex algorithms you can use RunJS

5 Likes

Thanks, @Apple. That helped a lot to get me thinking “Wappler”.

One of my faults was, for example, that I added a “data” variable of type “Object” to my post, but to access the values, I don’t need to access $_POST.data.field but simply $_POST.field. Not sure if this is correct, I will investigate further :see_no_evil::upside_down_face:

Still looking for the documentation e.g. on the available steps (found a bit in the extension manager)…

Not sure about the response step you mentioned, isn’t it for setting response code and message? (But I think I got it now with custom response objects: construct a JSON via set value and or groups, that’s the way?

The documentation is sadly still nearly non-existing. I suggest to mostly use the community with come creative search terms to find the documentation you need in the end.

The server actions return a JSON object by default. A good way to get an idea of what’s happening is like this:


In a server action, set a value (1). Play around with the properties (2). For example you can set $_POST in the value, to see what your object looks like. Then open the server action in your browser (3) to execute it (this wouldn’t work well with a form, in that case you can use devtools and the network tab to check the result)

As for the group step and response, this is what @Apple means:

Result when opening that server action in the browser: image

Notes:

  • See how ‘testing_value’ isn’t seen in the browser? if I disable the ‘response’ step it outputs all the variables like this:
    image
    image
    (globalidentity is a global value I set up for my application)
  • Make sure the ‘output’ is on whenever you need to see something back in the front-end
2 Likes

I’m assuming the console.log thingy was not an issue after all as you edited the post. I was about to start some testing. Can you confirm?

Yes. I think my server was just totally confused with me messing around. After quitting everything, killing the Wappler Helper (again) and restart from scratch, it worked as expected. Thank you for asking.

I have actually some trouble from time to time with the server (on Mac OS) either not properly responding, or responding only every second time, or Wapper telling me on startup that the port is already in use (so I have to manually kill the process)…

That’s what I currently do, also to avoid to many silly questions - That’s actually one of my biggest “issues” with subscribing: Wappler is not on the cheap side with the actual pricing, so my expectations are realtively high, also the frustration level when you want to get something done.

Understood. Just checked some of my testing, I never used send response for 200s, only for 404 or anything other that doesn’t return a value. That’s where my confusion comes from.

EDIT; This took me a second… without response, all data set to “output” is returned to the caller / browser, with the response step, only the selected object (or whatever is set in the text) is send. Makes totally sense an I just didn’t get it :see_no_evil:

Yes!!

Haha whatever you do, don’t feel dumb. I know that I have these moments almost daily…
Sometimes it just doesn’t click.
Or sometimes I’m spending 53 minutes banging my head against the wall because my code doesn’t work, and then realise I wrote kull instead of null

Relatable. I was on the verge of looking for alternatives MANY times in my first few months of using Wappler. Mostly because it felt unstable to develop an application with this, while not having priority support AND all documentation available.
But, I don’t have a single regret sticking with Wappler. I have been able to overcome this unstable feeling by increasing my own skills and understanding. So even if there’s some bugs or things not working as expected, I know I can make a workaround and rely on the community to help me out.

3 Likes

The challenge for me is: I am looking into no/low code for decades now (Filemaker, MicroBrew/AppWare, FoxPro, 4D, HyperCard, Authorware, just to name a few), as an alternative to get something done quickly, something where I don’t have to code. At the moment, it feels like I would spend more time on Wappler than doing it in Typescript/PHP/Java directly :joy:

On the other hand, there are a offerings for Frontend creation and a bit of Backend like RapidWeaver with Stacks, Bootstrap Studio, but Wappler as an integrated environment with full source code support looks quite different.

Okay, thanks all. I think I am getting it now :joy:

API Prototype runs. Now some frontend design and rock it.

4 Likes

Looks like a fun project you’re working on :slight_smile:

What’s this image

A remake of a multiuser game I’ve done some years ago for the Pebble Smartwatch:

It’s across all disciplnes: Game Server, API, Backend/Administration, Website and mobile app as the game client. A good fit for Wappler, I think.

Thats a Loupe Deck Live, a programmable keyboard to launch events / shortcuts / control software, I use it mainly for Photoshop, Capture One (I am a hobby photographer) and for MS Teams.

2 Likes

Wow didn’t expect someone to be making a game with Wappler!

That’s awesome, thanks for sharing

1 Like