Replies: 4 comments 1 reply
-
I just thought of it, we can also integrate in the same way to a backend already written in nodeJS (as well as other JSII compatible languaguges!) |
Beta Was this translation helpful? Give feedback.
-
I love that we're already talking about this stuff. We need this! Here's some feedback:
So, what if:
For example:
import React, { useState, useEffect } from 'react';
import { createApiClient } from "@winglang/client"; // Our standard implementation. Can use your own
import { myApi } from "../wing"; // Generated file, do not touch. Includes URL, routes and their types
const { increaseCounter, peekCounter, peek } = createApiClient(myApi); // Typed client
function Example() {
const [count, setCount] = useState(0);
const increase = async () => {
// this wing-exposed fn is already error proof 🤩
const res = await increaseCounter();
setCount(res.body);
}
const peek = async () => {
// this wing-exposed fn is already error proof 🤩
const res = await peekCounter();
setCount(res.body);
}
useEffect(() => {
// will initiate the counter value on load
myApi.peek();
}, []);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={increase}>
Click me
</button>
</div>
);
} |
Beta Was this translation helpful? Give feedback.
-
One way to think about this is that web apps are not very different from inflight code. The fact that they run on client browser computer and not in a cloud compute platform doesn't change the inflight/preflight nature of this relationship. We've actually prototyped stuff like this in one of the offsite where we implemented a |
Beta Was this translation helpful? Give feedback.
-
Maybe we should consider adding another resource bring cloud;
bring http;
let api = new cloud.Api();
let counter = new cloud.Counter();
let increase = inflight (): Json => {
return { body: counter.inc() + 1 };
};
let peek = inflight (): Json => {
return { body: counter.peek() };
};
// public API
api.post("/counter", increase);
api.get("/counter", peek);
let sdk = new js.SDK();
// this SDK relies on our public API
sdk.addFunction("increase", inflight ():http.Response => {
return http.get(api.url + "/counter");
});
// this SDK call relies on a private API (there is no API)
sdk.addFunction("peek", inflight ():http.Response => {
return peek();
}); |
Beta Was this translation helpful? Give feedback.
-
I was thinking about how to make Wing more appealing to website developers, keeping in mind that the connectivity between the two should be seamless, and work both on sim and the cloud.
I came out with this interesting approach, and I would love to hear what you think about it.
I'll start with the end:
what if:
expose
keyword to expose a function to the website js files:for example:
will be equivalent of:
other option is:
(this way if we want to supply domain or to tweak an existing API instance, we definitely can)
The "npm start" command starts the simulator, and "npm build/serve" will deploy to the chosen target (specified in the configuration file as well)
Beta Was this translation helpful? Give feedback.
All reactions