lambder 1.0.67 → 1.0.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/Readme.md +14 -7
  2. package/package.json +1 -1
package/Readme.md CHANGED
@@ -35,8 +35,10 @@ const lambder = new Lambder({
35
35
  });
36
36
 
37
37
  // Define a simple api
38
- lambder.addApi("fetchData", async (ctx, res) => {
39
- const data = await fetchDataSomehow();
38
+ lambder.addApi("getCompanyPage", async (ctx, res) => {
39
+ const { host, path, get, post, cookie, headers } = ctx;
40
+ const companyName = post.payload.companyName;
41
+ const data = await fetchDataSomehow(companyName);
40
42
  return res.api({ payload: data });
41
43
  });
42
44
 
@@ -45,6 +47,14 @@ lambder.addRoute("/hello-world", (ctx, res) => {
45
47
  return res.json({ message: "Hello World" });
46
48
  });
47
49
 
50
+ // Route with parameters
51
+ lambder.addRoute("/user/:userId", async (ctx, res) => {
52
+ const user = await getUser(ctx.pathParams.userId);
53
+ if(!user) return res.status404("Not found");
54
+
55
+ return res.json({ message: `Hello ${user.name}` });
56
+ });
57
+
48
58
  // Match all other paths and serve static files from publicPath, if not found, serve index.html
49
59
  lambder.addRoute("*", (ctx, res)=>{
50
60
  return res.file(ctx.path, {}, "index.html");
@@ -73,16 +83,13 @@ export const handler = (event, context) => {
73
83
  // Before render hook example
74
84
  lambder.addHook("beforeRender", async (ctx, res) => {
75
85
  // Perform actions before rendering
76
- if(ctx.method === "POST") {
77
- // Validate CSRF token, for example
78
- }
79
86
  return ctx; // Return modified context or throw an Error
80
87
  });
81
88
  ```
82
89
 
83
90
  ## Frontend Usage with LambderCaller
84
91
 
85
- LambderCaller is a frontend companion library for Lambder, designed to simplify making API requests to your Lambder backend services.
92
+ LambderCaller is a frontend companion library for Lambder, it is only 2kb compressed, and designed to simplify making API requests to your Lambder backend services.
86
93
 
87
94
  ### Installing LambderCaller
88
95
 
@@ -113,7 +120,7 @@ const lambderCaller = new LambderCaller({
113
120
  const loadPageData = async () => {
114
121
  try {
115
122
  const response = await lambderCaller.api("getCompanyPage", {
116
- subdomain: "example", // Pass necessary parameters for your API call
123
+ companyName: "example", // Pass necessary parameters for your API call
117
124
  });
118
125
  } catch (error) {
119
126
  console.error("Failed to fetch page data:", error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambder",
3
- "version": "1.0.67",
3
+ "version": "1.0.69",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",