What is the default value *`defaultPayloadFormatVe...
# help
ö
What is the default value
defaultPayloadFormatVersion
for
sst.Api
, is it
sst.ApiPayloadFormatVersion.V1
or
sst.ApiPayloadFormatVersion.V2
?
t
I believe it's v2
yep
Copy code
this.defaultPayloadFormatVersion ||
      ApiPayloadFormatVersion.V2;
b
Same. I remember initially when using SST with an existing gateway it caused issues.
Ha, as I was typing you verified it... I tried to be helpful 😂
ö
So V1 is the one that is compatible with API Gateway’s REST API rişght?
and v2 is HTTP Api
b
That's how I understand it.
a
Me too.
I moved all my APIs from v1 to v2.
Once I moved to SST.
ö
I didnt know that you can configure the payload
Are we sure that we can? lol
a
Give it a try.
ö
For example passing sst.ApiPayloadFormatVersion.V1
I’m scared lol
a
Just migrate to v2 😂 .
I’ve migrated to v2 and my life is better now.
ö
Why
a
I like it more, from Console it’s easier to manage, haha.
v1 it’s shitty.
ö
really
well v1 is a bit complicated to be honest
a
Yeah I hate it.
ö
but I guess provides you more control and more features
a
v2 also has better custom authorizer.
ö
tho honestly i use none of them
peh
a
Haha.
Maybe is even easier to migrate then.
Maybe the only change you need to do is over sobre query parameters handler.
ö
I’ve used it before actually
but seems like the type definition for `APIGatewayProxyHandlerV2`is broken or idk
it has changed
This doesnt raise any error for TS
Copy code
import { APIGatewayProxyHandlerV2 } from 'aws-lambda'

export const main: APIGatewayProxyHandlerV2 = async (evt, ctx, cb) => {

      return {

      }
}
t
Yeah technically all the fields are optional
ö
Oh I’m surprised
How so?
Doesnt API gateway expect a proper response?
Because I know it does for V1.
t
I'm not sure why they chose to type it that way
ö
For V1
Copy code
import { APIGatewayProxyHandler } from 'aws-lambda'

export const main = async (evt, ctx, cb) => {

}
This gives error, telling that you gotta return at least
statusCode
and
body
By the way do you think this is a bug: I wanted to try a deploy
sst.Api
with customDomain, however, I only provided the
domainName
, and TS gave no error:
Copy code
const api = new sst.Api(this, 'Api', {
      customDomain: {
            domainName: 'mynonexistentcustomdomainthatmightfail',
      },
      routes: {
            "GET    /api": handlerDir + "api/index.main"
      }
})
t
TS wouldn't be able to infer that the domain doesn't exist at compile time if I'm understanding you correctly
ö
Oh if it is the case fine, but I thought that you explicitly need to provide
hostedZoneId
t
If the domainName is the same as the zone I think we don't need you to pass in the zone
ö
I see
Can’t we pass description for the Api?
to here basically:
or to Stage
t
Copy code
new Api(stack, "Api", { httpApi: { description: "Hello" } })
ö
How do you send an array or object in queryStringParameters in V2?
Oh you cant… it is always a string
😞
a
Yeah alway string.
Is what I mentioned before.
Then how do you deal with it? It was easy using
multiValueQueryString
property
a
You need to do the parsing in your side.
ö
Yeah damn
lol
Hey Format V2 users 😄 Any idea why?
👀
More 👀
t
There is a slight issue in tsserver with returning a promise wrapped object
You can ignore the
then
- it'll already be there because of the
async
flag on the function
The first error is because you need to return at minimum
{}
from that handler for the type to be valid
ö
Yeah but it is typed as never
which is confusing to me
t
Yeah that has to do with the type inference, bit hard to explain by you can type the body as well which is what that <generic> argument is. When returning void that type cannot exist which is why it's printing
never
^ that explanation is probably useless haha - just one of those things you start to understand after seeing it a lot