2.1.0
What's Changed
- Remove
NextApiOgImageQuery<QueryType>
.
Instead use TypeScript built in Record type like this:Record<QueryType, string>
- Create option to provide different params passing strategy (GET, query) (POST, JSON body) by @neg4n in #15
-
From now on,
next-api-og-image
allows you to choose strategy for providing values to the template. -
Available strategies:
query
(default) - values are passed by query params and GET HTTP request.
These values ⛔️ cannot be nested nor accessed by nested destructuring in template provider function.body
- values are passed by POST HTTP request and JSON body.
These values ✅ can be nested and accessed by nested destructuring in template provider function.
The strategies are determined by
strategy
prop in the configuration. Default strategy isquery
.⚠️ NOTE
Regardless of the strategy - all properties (every single one)
are implicitly casted to string, even very long JSON's nested values -
TypeScript usage
If you're using TypeScript, you probably want to have these things
typed. Well... its actually super easy! Simply add generic types towithOGImage
function.- typed
query
strategy with query params?foo=hello&bar=friend
will look like this:
export default withOGImage<'query', 'foo' | 'bar'>(/* ... */)
- typed
body
strategy with JSON payload{ "foo": "hello", "imNested": { "bar": "friend" }}
will look like this:
export default withOGImage<'body', { foo: string, imNested: { bar: string } }>({ strategy: 'body', /* ... */ })
- typed
-
Strategy errors
When strategy is set to
query
and you're sending POST HTTP request with JSON body or when strategy is set tobody
and you're sending GET HTTP request with query params -next-api-og-image
will:- Will throw an runtime error
- Set appropiate response message to the client
You can disable this behaviour by settingdev: { errorsInResponse: false }
in the configuration
-
Feel free to open discussion if you have any questions!
Examples (added examples using strategies!): https://github.com/neg4n/next-api-og-image/tree/2.1.0#examples
Full Changelog: 2.0.0...2.1.0