Hello guys. Is there any example/documentation or ...
# sst
a
Hello guys. Is there any example/documentation or anybody can provide ideas on how to re-use an API Gateway from SST? For example I have 2 Serverless Framework projects that use the same GW base path. Like.. Service one uses
/tasks
and service 2 uses
/tasks/{id}/responses
… Currently what I do is exporting the GW ID into CF from a parent SLS project and re-using that ID on the child projects (service 1 and 2). How is this pattern supposed to be done on SST? Should I have 1 parent-stack and somehow reuse it from my 2 child projects? I’m in the process of investigating what is needed to migrate my infrastructure from SLS to SST.
f
Hey @Adrián Mouly, you can share an API endpoint in SST like this:
Copy code
// stackA.js: create the api
this.api = new sst.Api(this, "MyApi", ...);

// index.js: pass the api to stackB's props
const stackA = new StackA(app, "stackA");
new StackB(app, "stackB", { api: stackA.api });

// stackB.js: add additional routes
props.api.addRoutes(this, ...);
It’s worth deciding if you want to use HTTP Api or REST Api. It’s much easier to share endpoints with HTTP Api.
For example, imaging if you have 3 stacks with: • stackA has route: / • stackB has route: /tasks • stackC has route: /tasks/{id}/responses
With REST Api, stackB depends on stackA, and stackC depends on StackB.
With HTTP Api, both stackB and stackC depends on stackA (the root)
So as you add more stacks, they will all depend on stackA. The inter-stack dependencies are much simpler.
a
Thank you @Frank! going to take a look on it. I’ve been using SLS so not sure if that uses HTTP or REST, but I think is rest.
m
@Adrián Mouly, You can check from console at api gateway to see if the type is REST of HTTP. Or else.. in sls framework.
httpApi
looks like this
Copy code
functions:
  simple:
    handler: handler.simple
    events:
      - httpApi: 'PATCH /elo'
  extended:
    handler: handler.extended
    events:
      - httpApi:
          method: POST
          path: /post/just/to/this/path
where as REST API looks like this,
Copy code
candidateDetails:
    handler: api/candidate.get
    events:
      - http:
          path: candidates/{id}
          method: get
P.S - I never used sls, I looked these up. Let me know if you agree.
a
Oh that makes sense.
The difference is
http
and
httpApi
, hahaha.
Yeah I been using REST I believe.
Not sure why they created HTTP API, it’s so similar.
m
I was doing the same. REST is still feature rich than HTTP, but http is faster(a lot) and cheaper. Check out the diff here. I was doing body validations as well at my rest API, but even then I switched to HTTP and doing validations in lambdas. Performance claims holds. but I still need do do some testing to see if I am actually benefiting cost wise.
a
Yeah I do validations on the lambda with Class-validator or JOI.
Interesting that HTTP API has integration with Cloud Map.
This is interesting to build a service-mesh-like platform.