@innet/server 1.7.1 → 2.0.0-alpha.0
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.
- package/README.md +3065 -476
- package/constants.d.ts +4 -1
- package/constants.es6.js +10 -2
- package/constants.js +11 -2
- package/declaration.d.ts +9 -0
- package/example/app/App/App.d.ts +1 -0
- package/example/app/App/index.d.ts +1 -0
- package/example/index.d.ts +1 -0
- package/example/requests/index.d.ts +1 -0
- package/example/requests/partners/EditPartner/EditPartner.d.ts +1 -0
- package/example/requests/partners/EditPartner/index.d.ts +1 -0
- package/example/requests/partners/GetPartner/GetPartner.d.ts +1 -0
- package/example/requests/partners/GetPartner/index.d.ts +1 -0
- package/example/requests/partners/GetPartners/GetPartners.d.ts +1 -0
- package/example/requests/partners/GetPartners/index.d.ts +1 -0
- package/example/requests/partners/index.d.ts +3 -0
- package/example/schemas/address/AddressSchema/AddressSchema.d.ts +1 -0
- package/example/schemas/address/AddressSchema/index.d.ts +1 -0
- package/example/schemas/address/index.d.ts +1 -0
- package/example/schemas/app/ListSchema/ListSchema.d.ts +1 -0
- package/example/schemas/app/ListSchema/index.d.ts +1 -0
- package/example/schemas/app/index.d.ts +1 -0
- package/example/schemas/index.d.ts +4 -0
- package/example/schemas/location/LocationSchema/LocationSchema.d.ts +1 -0
- package/example/schemas/location/LocationSchema/index.d.ts +1 -0
- package/example/schemas/location/index.d.ts +1 -0
- package/example/schemas/partner/EditPartnerSchema/EditPartnerSchema.d.ts +1 -0
- package/example/schemas/partner/EditPartnerSchema/index.d.ts +1 -0
- package/example/schemas/partner/PartnerSchema/PartnerSchema.d.ts +1 -0
- package/example/schemas/partner/PartnerSchema/index.d.ts +1 -0
- package/example/schemas/partner/index.d.ts +2 -0
- package/example/tags/Partner/Partner.d.ts +1 -0
- package/example/tags/Partner/index.d.ts +1 -0
- package/example/tags/index.d.ts +1 -0
- package/handler/handler.d.ts +96 -58
- package/handler/handler.es6.js +102 -63
- package/handler/handler.js +100 -65
- package/handler/index.d.ts +1 -1
- package/hooks/index.d.ts +25 -6
- package/hooks/index.es6.js +25 -6
- package/hooks/index.js +25 -18
- package/hooks/useAction/index.d.ts +1 -1
- package/hooks/useAction/useAction.d.ts +4 -4
- package/hooks/useAction/useAction.es6.js +9 -7
- package/hooks/useAction/useAction.js +9 -7
- package/hooks/useApi/index.d.ts +1 -0
- package/hooks/useApi/index.es6.js +1 -0
- package/hooks/useApi/index.js +10 -0
- package/hooks/useApi/useApi.d.ts +13 -0
- package/hooks/useApi/useApi.es6.js +12 -0
- package/hooks/useApi/useApi.js +17 -0
- package/hooks/useBlock/index.d.ts +1 -0
- package/hooks/useBlock/index.es6.js +1 -0
- package/hooks/{useFiles → useBlock}/index.js +2 -2
- package/hooks/useBlock/useBlock.d.ts +2 -0
- package/hooks/useBlock/useBlock.es6.js +14 -0
- package/hooks/useBlock/useBlock.js +18 -0
- package/hooks/useBody/index.d.ts +1 -1
- package/hooks/useBody/useBody.d.ts +1 -1
- package/hooks/useBody/useBody.es6.js +3 -2
- package/hooks/useBody/useBody.js +3 -2
- package/hooks/useBodyFile/index.d.ts +1 -0
- package/hooks/useBodyFile/index.es6.js +1 -0
- package/hooks/useBodyFile/index.js +10 -0
- package/hooks/useBodyFile/useBodyFile.d.ts +3 -0
- package/hooks/useBodyFile/useBodyFile.es6.js +14 -0
- package/hooks/useBodyFile/useBodyFile.js +19 -0
- package/hooks/useComponentName/index.d.ts +1 -0
- package/hooks/useComponentName/index.es6.js +1 -0
- package/hooks/useComponentName/index.js +9 -0
- package/hooks/useComponentName/useComponentName.d.ts +1 -0
- package/hooks/useComponentName/useComponentName.es6.js +8 -0
- package/hooks/useComponentName/useComponentName.js +12 -0
- package/hooks/useCookies/index.d.ts +1 -1
- package/hooks/useCookies/useCookies.d.ts +1 -2
- package/hooks/useCookies/useCookies.es6.js +3 -2
- package/hooks/useCookies/useCookies.js +3 -2
- package/hooks/useEndpoint/index.d.ts +1 -0
- package/hooks/useEndpoint/index.es6.js +1 -0
- package/hooks/useEndpoint/index.js +10 -0
- package/hooks/useEndpoint/useEndpoint.d.ts +10 -0
- package/hooks/useEndpoint/useEndpoint.es6.js +12 -0
- package/hooks/useEndpoint/useEndpoint.js +17 -0
- package/hooks/useHeaders/index.d.ts +1 -0
- package/hooks/useHeaders/index.es6.js +1 -0
- package/hooks/useHeaders/index.js +9 -0
- package/hooks/useHeaders/useHeaders.d.ts +3 -0
- package/hooks/useHeaders/useHeaders.es6.js +8 -0
- package/hooks/useHeaders/useHeaders.js +12 -0
- package/hooks/useHost/index.d.ts +1 -0
- package/hooks/useHost/index.es6.js +1 -0
- package/hooks/useHost/index.js +10 -0
- package/hooks/useHost/useHost.d.ts +7 -0
- package/hooks/useHost/useHost.es6.js +12 -0
- package/hooks/useHost/useHost.js +17 -0
- package/hooks/useNewSchema/index.d.ts +1 -0
- package/hooks/useNewSchema/index.es6.js +1 -0
- package/hooks/useNewSchema/index.js +9 -0
- package/hooks/useNewSchema/useNewSchema.d.ts +2 -0
- package/hooks/useNewSchema/useNewSchema.es6.js +32 -0
- package/hooks/useNewSchema/useNewSchema.js +36 -0
- package/hooks/useObjectRule/index.d.ts +1 -0
- package/hooks/useObjectRule/index.es6.js +1 -0
- package/hooks/useObjectRule/index.js +10 -0
- package/hooks/useObjectRule/useObjectRule.d.ts +4 -0
- package/hooks/useObjectRule/useObjectRule.es6.js +14 -0
- package/hooks/useObjectRule/useObjectRule.js +19 -0
- package/hooks/useOneElementError/index.d.ts +1 -0
- package/hooks/useOneElementError/index.es6.js +1 -0
- package/hooks/useOneElementError/index.js +9 -0
- package/hooks/useOneElementError/useOneElementError.d.ts +1 -0
- package/hooks/useOneElementError/useOneElementError.es6.js +8 -0
- package/hooks/useOneElementError/useOneElementError.js +12 -0
- package/hooks/useParam/index.d.ts +1 -0
- package/hooks/useParam/index.es6.js +1 -0
- package/hooks/useParam/index.js +10 -0
- package/hooks/useParam/useParam.d.ts +7 -0
- package/hooks/useParam/useParam.es6.js +12 -0
- package/hooks/useParam/useParam.js +17 -0
- package/hooks/useParams/index.d.ts +1 -0
- package/hooks/useParams/index.es6.js +1 -0
- package/hooks/useParams/index.js +10 -0
- package/hooks/useParams/useParams.d.ts +3 -0
- package/hooks/useParams/useParams.es6.js +8 -0
- package/hooks/useParams/useParams.js +13 -0
- package/hooks/useParentRule/index.d.ts +1 -0
- package/hooks/useParentRule/index.es6.js +1 -0
- package/hooks/useParentRule/index.js +10 -0
- package/hooks/useParentRule/useParentRule.d.ts +4 -0
- package/hooks/useParentRule/useParentRule.es6.js +10 -0
- package/hooks/useParentRule/useParentRule.js +15 -0
- package/hooks/usePath/index.d.ts +1 -0
- package/hooks/usePath/index.es6.js +1 -0
- package/hooks/usePath/index.js +9 -0
- package/hooks/usePath/usePath.d.ts +1 -0
- package/hooks/usePath/usePath.es6.js +8 -0
- package/hooks/{useFiles/useFiles.js → usePath/usePath.js} +4 -3
- package/hooks/useRequest/index.d.ts +1 -0
- package/hooks/useRequest/index.es6.js +1 -0
- package/hooks/useRequest/index.js +10 -0
- package/hooks/useRequest/useRequest.d.ts +5 -0
- package/hooks/useRequest/useRequest.es6.js +8 -0
- package/hooks/useRequest/useRequest.js +13 -0
- package/hooks/useResponse/index.d.ts +1 -0
- package/hooks/useResponse/index.es6.js +1 -0
- package/hooks/useResponse/index.js +10 -0
- package/hooks/useResponse/useResponse.d.ts +5 -0
- package/hooks/useResponse/useResponse.es6.js +8 -0
- package/hooks/useResponse/useResponse.js +13 -0
- package/hooks/useRule/index.d.ts +1 -0
- package/hooks/useRule/index.es6.js +1 -0
- package/hooks/useRule/index.js +11 -0
- package/hooks/useRule/useRule.d.ts +6 -0
- package/hooks/useRule/useRule.es6.js +17 -0
- package/hooks/useRule/useRule.js +23 -0
- package/hooks/useSchemaContext/index.d.ts +1 -0
- package/hooks/useSchemaContext/index.es6.js +1 -0
- package/hooks/useSchemaContext/index.js +10 -0
- package/hooks/useSchemaContext/useSchemaContext.d.ts +5 -0
- package/hooks/useSchemaContext/useSchemaContext.es6.js +8 -0
- package/hooks/useSchemaContext/useSchemaContext.js +13 -0
- package/hooks/useSchemaType/index.d.ts +1 -0
- package/hooks/useSchemaType/index.es6.js +1 -0
- package/hooks/useSchemaType/index.js +9 -0
- package/hooks/useSchemaType/useSchemaType.d.ts +4 -0
- package/hooks/useSchemaType/useSchemaType.es6.js +32 -0
- package/hooks/useSchemaType/useSchemaType.js +36 -0
- package/hooks/useSearch/index.d.ts +1 -1
- package/hooks/useSearch/useSearch.d.ts +1 -1
- package/hooks/useSearch/useSearch.es6.js +9 -2
- package/hooks/useSearch/useSearch.js +9 -2
- package/hooks/useServer/index.d.ts +1 -1
- package/hooks/useServer/useServer.d.ts +11 -7
- package/hooks/useServer/useServer.es6.js +7 -7
- package/hooks/useServer/useServer.js +7 -7
- package/hooks/useTag/index.d.ts +1 -0
- package/hooks/useTag/index.es6.js +1 -0
- package/hooks/useTag/index.js +10 -0
- package/hooks/useTag/useTag.d.ts +3 -0
- package/hooks/useTag/useTag.es6.js +8 -0
- package/hooks/useTag/useTag.js +13 -0
- package/hooks/useThrow/index.d.ts +1 -0
- package/hooks/useThrow/index.es6.js +1 -0
- package/hooks/useThrow/index.js +9 -0
- package/hooks/useThrow/useThrow.d.ts +1 -0
- package/hooks/useThrow/useThrow.es6.js +9 -0
- package/hooks/useThrow/useThrow.js +13 -0
- package/index.d.ts +6 -5
- package/index.es6.js +104 -21
- package/index.js +213 -45
- package/openApi.test.d.ts +1 -0
- package/package.json +27 -12
- package/{experimental/serverFn → plugins/handler}/index.d.ts +1 -1
- package/plugins/handler/index.es6.js +1 -0
- package/plugins/handler/index.js +4 -0
- package/plugins/handler/serverFn/index.d.ts +1 -0
- package/plugins/handler/serverFn/serverFn.d.ts +2 -0
- package/plugins/handler/serverFn/serverFn.es6.js +14 -0
- package/{experimental → plugins/handler}/serverFn/serverFn.js +9 -7
- package/plugins/index.d.ts +5 -15
- package/plugins/index.es6.js +5 -15
- package/plugins/index.js +5 -43
- package/plugins/main/api/api.d.ts +22 -0
- package/plugins/main/api/api.es6.js +180 -0
- package/plugins/main/api/api.js +188 -0
- package/plugins/main/api/index.d.ts +1 -0
- package/plugins/main/api/index.es6.js +1 -0
- package/plugins/{action → main/api}/index.js +2 -2
- package/plugins/main/body/body.d.ts +4 -0
- package/plugins/main/body/body.es6.js +55 -0
- package/plugins/main/body/body.js +63 -0
- package/plugins/main/body/index.d.ts +1 -0
- package/plugins/main/body/index.es6.js +1 -0
- package/plugins/main/body/index.js +9 -0
- package/plugins/main/contact/contact.d.ts +10 -0
- package/plugins/main/contact/contact.es6.js +16 -0
- package/plugins/main/contact/contact.js +20 -0
- package/plugins/main/contact/index.d.ts +1 -0
- package/plugins/main/contact/index.es6.js +1 -0
- package/plugins/main/contact/index.js +9 -0
- package/plugins/main/endpoint/endpoint.d.ts +37 -0
- package/plugins/main/endpoint/endpoint.es6.js +54 -0
- package/plugins/main/endpoint/endpoint.js +62 -0
- package/plugins/main/endpoint/index.d.ts +1 -0
- package/plugins/main/endpoint/index.es6.js +1 -0
- package/plugins/main/endpoint/index.js +9 -0
- package/plugins/main/fallback/fallback.d.ts +4 -0
- package/plugins/main/fallback/fallback.es6.js +19 -0
- package/plugins/main/fallback/fallback.js +23 -0
- package/plugins/main/fallback/index.d.ts +1 -0
- package/plugins/main/fallback/index.es6.js +1 -0
- package/plugins/main/fallback/index.js +9 -0
- package/plugins/main/host/host.d.ts +16 -0
- package/plugins/main/host/host.es6.js +26 -0
- package/plugins/main/host/host.js +34 -0
- package/plugins/main/host/index.d.ts +1 -0
- package/plugins/main/host/index.es6.js +1 -0
- package/plugins/main/host/index.js +9 -0
- package/plugins/main/index.d.ts +13 -0
- package/plugins/main/index.es6.js +13 -0
- package/plugins/main/index.js +16 -0
- package/plugins/main/license/index.d.ts +1 -0
- package/plugins/main/license/index.es6.js +1 -0
- package/plugins/main/license/index.js +9 -0
- package/plugins/main/license/license.d.ts +21 -0
- package/plugins/main/license/license.es6.js +15 -0
- package/plugins/main/license/license.js +19 -0
- package/plugins/main/param/index.d.ts +1 -0
- package/plugins/main/param/index.es6.js +1 -0
- package/plugins/main/param/index.js +9 -0
- package/plugins/main/param/param.d.ts +35 -0
- package/plugins/main/param/param.es6.js +63 -0
- package/plugins/main/param/param.js +71 -0
- package/plugins/main/request/index.d.ts +1 -0
- package/plugins/main/request/index.es6.js +1 -0
- package/plugins/main/request/index.js +9 -0
- package/plugins/main/request/request.d.ts +4 -0
- package/plugins/main/request/request.es6.js +21 -0
- package/plugins/main/request/request.js +25 -0
- package/plugins/main/response/index.d.ts +1 -0
- package/plugins/main/response/index.es6.js +1 -0
- package/plugins/main/response/index.js +9 -0
- package/plugins/main/response/response.d.ts +16 -0
- package/plugins/main/response/response.es6.js +44 -0
- package/plugins/main/response/response.js +52 -0
- package/plugins/{server → main/server}/index.d.ts +1 -1
- package/plugins/main/server/server.d.ts +13 -0
- package/plugins/main/server/server.es6.js +44 -0
- package/plugins/main/server/server.js +55 -0
- package/plugins/main/tag/index.d.ts +1 -0
- package/plugins/main/tag/index.es6.js +1 -0
- package/plugins/main/tag/index.js +9 -0
- package/plugins/main/tag/tag.d.ts +11 -0
- package/plugins/main/tag/tag.es6.js +29 -0
- package/plugins/main/tag/tag.js +37 -0
- package/plugins/main/variable/index.d.ts +1 -0
- package/plugins/main/variable/index.es6.js +1 -0
- package/plugins/main/variable/index.js +9 -0
- package/plugins/main/variable/variable.d.ts +24 -0
- package/plugins/main/variable/variable.es6.js +16 -0
- package/plugins/main/variable/variable.js +20 -0
- package/plugins/request/cms/cms.d.ts +5 -0
- package/plugins/request/cms/cms.es6.js +24 -0
- package/plugins/request/cms/cms.js +33 -0
- package/plugins/{cms → request/cms}/index.d.ts +1 -1
- package/plugins/request/cookie/cookie.d.ts +7 -0
- package/plugins/request/cookie/cookie.es6.js +28 -0
- package/plugins/request/cookie/cookie.js +36 -0
- package/plugins/{cookie → request/cookie}/index.d.ts +1 -1
- package/plugins/{error → request/error}/error.d.ts +60 -61
- package/plugins/{error → request/error}/error.es6.js +70 -70
- package/plugins/{error → request/error}/error.js +70 -75
- package/plugins/{error → request/error}/index.d.ts +1 -1
- package/plugins/request/file/file.d.ts +4 -0
- package/plugins/request/file/file.es6.js +38 -0
- package/plugins/request/file/file.js +48 -0
- package/plugins/{file → request/file}/index.d.ts +1 -1
- package/plugins/request/header/header.d.ts +6 -0
- package/plugins/request/header/header.es6.js +15 -0
- package/plugins/request/header/header.js +19 -0
- package/plugins/{header → request/header}/index.d.ts +1 -1
- package/plugins/request/index.d.ts +8 -0
- package/plugins/request/index.es6.js +8 -0
- package/plugins/request/index.js +11 -0
- package/plugins/{proxy → request/proxy}/index.d.ts +1 -1
- package/plugins/request/proxy/index.es6.js +1 -0
- package/plugins/{proxy → request/proxy}/index.js +0 -1
- package/plugins/request/proxy/proxy.d.ts +6 -0
- package/plugins/request/proxy/proxy.es6.js +20 -0
- package/plugins/request/proxy/proxy.js +28 -0
- package/plugins/{redirect → request/redirect}/index.d.ts +1 -1
- package/plugins/{redirect → request/redirect}/redirect.d.ts +17 -19
- package/plugins/request/redirect/redirect.es6.js +41 -0
- package/plugins/request/redirect/redirect.js +46 -0
- package/plugins/{success → request/success}/index.d.ts +1 -1
- package/plugins/{success → request/success}/success.d.ts +17 -19
- package/plugins/request/success/success.es6.js +33 -0
- package/plugins/request/success/success.js +38 -0
- package/plugins/schema/array/array.d.ts +5 -0
- package/plugins/schema/array/array.es6.js +58 -0
- package/plugins/schema/array/array.js +66 -0
- package/plugins/schema/array/index.d.ts +1 -0
- package/plugins/schema/array/index.es6.js +1 -0
- package/plugins/schema/array/index.js +9 -0
- package/plugins/schema/binary/binary.d.ts +9 -0
- package/plugins/schema/binary/binary.es6.js +39 -0
- package/plugins/schema/binary/binary.js +43 -0
- package/plugins/schema/binary/index.d.ts +1 -0
- package/plugins/schema/binary/index.es6.js +1 -0
- package/plugins/schema/binary/index.js +9 -0
- package/plugins/schema/boolean/boolean.d.ts +5 -0
- package/plugins/schema/boolean/boolean.es6.js +32 -0
- package/plugins/schema/boolean/boolean.js +36 -0
- package/plugins/schema/boolean/index.d.ts +1 -0
- package/plugins/schema/boolean/index.es6.js +1 -0
- package/plugins/schema/boolean/index.js +9 -0
- package/plugins/schema/date/date.d.ts +8 -0
- package/plugins/schema/date/date.es6.js +64 -0
- package/plugins/schema/date/date.js +68 -0
- package/plugins/schema/date/index.d.ts +1 -0
- package/plugins/schema/date/index.es6.js +1 -0
- package/plugins/schema/date/index.js +9 -0
- package/plugins/schema/field/field.d.ts +6 -0
- package/plugins/schema/field/field.es6.js +46 -0
- package/plugins/schema/field/field.js +54 -0
- package/plugins/schema/field/index.d.ts +1 -0
- package/plugins/schema/field/index.es6.js +1 -0
- package/plugins/schema/field/index.js +9 -0
- package/plugins/schema/index.d.ts +12 -0
- package/plugins/schema/index.es6.js +12 -0
- package/plugins/schema/index.js +15 -0
- package/plugins/schema/integer/index.d.ts +1 -0
- package/plugins/schema/integer/index.es6.js +1 -0
- package/plugins/schema/integer/index.js +9 -0
- package/plugins/schema/integer/integer.d.ts +8 -0
- package/plugins/schema/integer/integer.es6.js +46 -0
- package/plugins/schema/integer/integer.js +50 -0
- package/plugins/schema/null/index.d.ts +1 -0
- package/plugins/schema/null/index.es6.js +1 -0
- package/plugins/schema/null/index.js +9 -0
- package/plugins/schema/null/null.d.ts +5 -0
- package/plugins/schema/null/null.es6.js +15 -0
- package/plugins/schema/null/null.js +19 -0
- package/plugins/schema/number/index.d.ts +1 -0
- package/plugins/schema/number/index.es6.js +1 -0
- package/plugins/schema/number/index.js +9 -0
- package/plugins/schema/number/number.d.ts +9 -0
- package/plugins/schema/number/number.es6.js +46 -0
- package/plugins/schema/number/number.js +50 -0
- package/plugins/schema/object/index.d.ts +1 -0
- package/plugins/schema/object/index.es6.js +1 -0
- package/plugins/schema/object/index.js +9 -0
- package/plugins/schema/object/object.d.ts +5 -0
- package/plugins/schema/object/object.es6.js +54 -0
- package/plugins/schema/object/object.js +62 -0
- package/plugins/schema/string/index.d.ts +1 -0
- package/plugins/schema/string/index.es6.js +1 -0
- package/plugins/schema/string/index.js +9 -0
- package/plugins/schema/string/string.d.ts +9 -0
- package/plugins/schema/string/string.es6.js +51 -0
- package/plugins/schema/string/string.js +55 -0
- package/plugins/schema/tuple/index.d.ts +1 -0
- package/plugins/schema/tuple/index.es6.js +1 -0
- package/plugins/schema/tuple/index.js +9 -0
- package/plugins/schema/tuple/tuple.d.ts +5 -0
- package/plugins/schema/tuple/tuple.es6.js +54 -0
- package/plugins/schema/tuple/tuple.js +62 -0
- package/plugins/schema/uuid/index.d.ts +1 -0
- package/plugins/schema/uuid/index.es6.js +1 -0
- package/plugins/schema/uuid/index.js +9 -0
- package/plugins/schema/uuid/uuid.d.ts +6 -0
- package/plugins/schema/uuid/uuid.es6.js +39 -0
- package/plugins/schema/uuid/uuid.js +43 -0
- package/plugins/utils/dev/dev.d.ts +4 -0
- package/plugins/utils/dev/dev.es6.js +10 -0
- package/plugins/utils/dev/dev.js +18 -0
- package/plugins/utils/dev/index.d.ts +1 -0
- package/plugins/utils/dev/index.es6.js +1 -0
- package/plugins/utils/dev/index.js +9 -0
- package/plugins/utils/dts/dts.d.ts +6 -0
- package/plugins/utils/dts/dts.es6.js +35 -0
- package/plugins/utils/dts/dts.js +44 -0
- package/plugins/utils/dts/index.d.ts +1 -0
- package/plugins/utils/dts/index.es6.js +1 -0
- package/plugins/utils/dts/index.js +9 -0
- package/plugins/utils/index.d.ts +4 -0
- package/plugins/utils/index.es6.js +4 -0
- package/plugins/utils/index.js +7 -0
- package/plugins/utils/prod/index.d.ts +1 -0
- package/plugins/utils/prod/index.es6.js +1 -0
- package/plugins/utils/prod/index.js +9 -0
- package/plugins/utils/prod/prod.d.ts +4 -0
- package/plugins/utils/prod/prod.es6.js +10 -0
- package/plugins/utils/prod/prod.js +18 -0
- package/plugins/utils/swagger/index.d.ts +1 -0
- package/plugins/utils/swagger/index.es6.js +1 -0
- package/plugins/utils/swagger/index.js +9 -0
- package/plugins/utils/swagger/swagger.d.ts +5 -0
- package/plugins/utils/swagger/swagger.es6.js +28 -0
- package/plugins/utils/swagger/swagger.html.es6.js +3 -0
- package/plugins/utils/swagger/swagger.html.js +7 -0
- package/plugins/utils/swagger/swagger.js +32 -0
- package/types.d.ts +76 -0
- package/types.es6.js +1 -0
- package/types.js +2 -0
- package/utils/FileData/Bin.d.ts +47 -0
- package/utils/FileData/Bin.es6.js +19 -0
- package/utils/FileData/Bin.js +23 -0
- package/utils/FileData/index.d.ts +1 -0
- package/utils/FileData/index.es6.js +1 -0
- package/utils/FileData/index.js +9 -0
- package/utils/JSONString/JSONString.d.ts +1 -0
- package/utils/JSONString/JSONString.es6.js +10 -0
- package/utils/JSONString/JSONString.js +14 -0
- package/utils/JSONString/index.d.ts +1 -0
- package/utils/JSONString/index.es6.js +1 -0
- package/utils/JSONString/index.js +9 -0
- package/utils/action/Action.d.ts +29 -0
- package/utils/action/Action.es6.js +125 -0
- package/utils/action/Action.js +134 -0
- package/utils/action/index.d.ts +1 -1
- package/utils/action/index.es6.js +1 -1
- package/utils/action/index.js +1 -3
- package/utils/dateFormat/dateFormat.d.ts +2 -0
- package/utils/dateFormat/dateFormat.es6.js +11 -0
- package/utils/dateFormat/dateFormat.js +15 -0
- package/utils/dateFormat/index.d.ts +1 -0
- package/utils/dateFormat/index.es6.js +1 -0
- package/utils/dateFormat/index.js +9 -0
- package/utils/decorators/index.d.ts +1 -0
- package/utils/decorators/index.es6.js +1 -0
- package/utils/decorators/index.js +4 -0
- package/utils/decorators/once/index.d.ts +1 -0
- package/utils/decorators/once/index.es6.js +1 -0
- package/utils/decorators/once/index.js +9 -0
- package/utils/decorators/once/once.d.ts +4 -0
- package/utils/decorators/once/once.es6.js +28 -0
- package/utils/decorators/once/once.js +32 -0
- package/utils/decorators/once/once.test.d.ts +1 -0
- package/utils/getEndpoint/getEndpoint.d.ts +2 -0
- package/utils/getEndpoint/getEndpoint.es6.js +31 -0
- package/utils/getEndpoint/getEndpoint.js +35 -0
- package/utils/getEndpoint/index.d.ts +1 -0
- package/utils/getEndpoint/index.es6.js +1 -0
- package/utils/getEndpoint/index.js +9 -0
- package/utils/getOrAdd/getOrAdd.d.ts +1 -0
- package/utils/getOrAdd/getOrAdd.es6.js +14 -0
- package/utils/getOrAdd/getOrAdd.js +18 -0
- package/utils/getOrAdd/index.d.ts +1 -0
- package/utils/getOrAdd/index.es6.js +1 -0
- package/utils/getOrAdd/index.js +9 -0
- package/utils/httpOnStart/httpOnStart.d.ts +2 -0
- package/utils/httpOnStart/httpOnStart.es6.js +5 -0
- package/utils/httpOnStart/httpOnStart.js +9 -0
- package/utils/httpOnStart/index.d.ts +1 -0
- package/utils/httpOnStart/index.es6.js +1 -0
- package/utils/httpOnStart/index.js +9 -0
- package/utils/index.d.ts +12 -3
- package/utils/index.es6.js +12 -3
- package/utils/index.js +12 -13
- package/{plugins → utils}/parseBody/index.d.ts +1 -1
- package/utils/parseBody/parseBody.d.ts +3 -0
- package/utils/parseBody/parseBody.es6.js +23 -0
- package/utils/parseBody/parseBody.js +27 -0
- package/utils/parseFormBody/index.d.ts +1 -0
- package/utils/parseFormBody/index.es6.js +1 -0
- package/utils/parseFormBody/index.js +9 -0
- package/utils/parseFormBody/parseFormBody.d.ts +3 -0
- package/utils/parseFormBody/parseFormBody.es6.js +56 -0
- package/utils/parseFormBody/parseFormBody.js +60 -0
- package/utils/parseSearch/index.d.ts +1 -1
- package/utils/parseSearch/index.es6.js +1 -1
- package/utils/parseSearch/index.js +1 -0
- package/utils/parseSearch/parseSearch.d.ts +3 -2
- package/utils/parseSearch/parseSearch.es6.js +6 -3
- package/utils/parseSearch/parseSearch.js +6 -3
- package/utils/parseSearch/parseSearch.test.d.ts +1 -0
- package/utils/rules/any/any.d.ts +1 -0
- package/utils/rules/any/any.es6.js +5 -0
- package/utils/rules/any/any.js +9 -0
- package/utils/rules/any/index.d.ts +1 -0
- package/utils/rules/any/index.es6.js +1 -0
- package/utils/rules/any/index.js +9 -0
- package/utils/rules/arrayOf/arrayOf.d.ts +2 -0
- package/utils/rules/arrayOf/arrayOf.es6.js +15 -0
- package/utils/rules/arrayOf/arrayOf.js +19 -0
- package/utils/rules/arrayOf/index.d.ts +1 -0
- package/utils/rules/arrayOf/index.es6.js +1 -0
- package/utils/rules/arrayOf/index.js +9 -0
- package/utils/rules/bin/bin.d.ts +2 -0
- package/utils/rules/bin/bin.es6.js +12 -0
- package/utils/rules/bin/bin.js +16 -0
- package/utils/rules/bin/index.d.ts +1 -0
- package/utils/rules/bin/index.es6.js +1 -0
- package/utils/rules/bin/index.js +9 -0
- package/utils/rules/binaryAccept/binaryAccept.d.ts +2 -0
- package/utils/rules/binaryAccept/binaryAccept.es6.js +32 -0
- package/utils/rules/binaryAccept/binaryAccept.js +36 -0
- package/utils/rules/binaryAccept/index.d.ts +1 -0
- package/utils/rules/binaryAccept/index.es6.js +1 -0
- package/utils/rules/binaryAccept/index.js +9 -0
- package/utils/rules/constants.d.ts +1 -0
- package/utils/rules/constants.es6.js +28 -0
- package/utils/rules/constants.js +32 -0
- package/utils/rules/dateTo/dateTo.d.ts +2 -0
- package/utils/rules/dateTo/dateTo.es6.js +11 -0
- package/utils/rules/dateTo/dateTo.js +15 -0
- package/utils/rules/dateTo/index.d.ts +1 -0
- package/utils/rules/dateTo/index.es6.js +1 -0
- package/utils/rules/dateTo/index.js +9 -0
- package/utils/rules/defaultTo/defaultTo.d.ts +1 -0
- package/utils/rules/defaultTo/defaultTo.es6.js +9 -0
- package/utils/rules/defaultTo/defaultTo.js +13 -0
- package/utils/rules/defaultTo/index.d.ts +1 -0
- package/utils/rules/defaultTo/index.es6.js +1 -0
- package/utils/rules/defaultTo/index.js +9 -0
- package/utils/rules/helpers.d.ts +8 -0
- package/utils/rules/helpers.es6.js +11 -0
- package/utils/rules/helpers.js +16 -0
- package/utils/rules/index.d.ts +29 -0
- package/utils/rules/index.es6.js +29 -0
- package/utils/rules/index.js +39 -0
- package/utils/rules/int/index.d.ts +1 -0
- package/utils/rules/int/index.es6.js +1 -0
- package/utils/rules/int/index.js +9 -0
- package/utils/rules/int/int.d.ts +2 -0
- package/utils/rules/int/int.es6.js +36 -0
- package/utils/rules/int/int.js +40 -0
- package/utils/rules/max/index.d.ts +1 -0
- package/utils/rules/max/index.es6.js +1 -0
- package/utils/rules/max/index.js +9 -0
- package/utils/rules/max/max.d.ts +1 -0
- package/utils/rules/max/max.es6.js +16 -0
- package/utils/rules/max/max.js +20 -0
- package/utils/rules/maxBin/index.d.ts +1 -0
- package/utils/rules/maxBin/index.es6.js +1 -0
- package/utils/rules/maxBin/index.js +9 -0
- package/utils/rules/maxBin/maxBin.d.ts +2 -0
- package/utils/rules/maxBin/maxBin.es6.js +13 -0
- package/utils/rules/maxBin/maxBin.js +17 -0
- package/utils/rules/maxDate/index.d.ts +1 -0
- package/utils/rules/maxDate/index.es6.js +1 -0
- package/utils/rules/maxDate/index.js +9 -0
- package/utils/rules/maxDate/maxDate.d.ts +1 -0
- package/utils/rules/maxDate/maxDate.es6.js +15 -0
- package/utils/rules/maxDate/maxDate.js +19 -0
- package/utils/rules/maxLength/index.d.ts +1 -0
- package/utils/rules/maxLength/index.es6.js +1 -0
- package/utils/rules/maxLength/index.js +9 -0
- package/utils/rules/maxLength/maxLength.d.ts +1 -0
- package/utils/rules/maxLength/maxLength.es6.js +16 -0
- package/utils/rules/maxLength/maxLength.js +20 -0
- package/utils/rules/min/index.d.ts +1 -0
- package/utils/rules/min/index.es6.js +1 -0
- package/utils/rules/min/index.js +9 -0
- package/utils/rules/min/min.d.ts +1 -0
- package/utils/rules/min/min.es6.js +16 -0
- package/utils/rules/min/min.js +20 -0
- package/utils/rules/minBin/index.d.ts +1 -0
- package/utils/rules/minBin/index.es6.js +1 -0
- package/utils/rules/minBin/index.js +9 -0
- package/utils/rules/minBin/minBin.d.ts +2 -0
- package/utils/rules/minBin/minBin.es6.js +13 -0
- package/utils/rules/minBin/minBin.js +17 -0
- package/utils/rules/minDate/index.d.ts +1 -0
- package/utils/rules/minDate/index.es6.js +1 -0
- package/utils/rules/minDate/index.js +9 -0
- package/utils/rules/minDate/minDate.d.ts +1 -0
- package/utils/rules/minDate/minDate.es6.js +15 -0
- package/utils/rules/minDate/minDate.js +19 -0
- package/utils/rules/minLength/index.d.ts +1 -0
- package/utils/rules/minLength/index.es6.js +1 -0
- package/utils/rules/minLength/index.js +9 -0
- package/utils/rules/minLength/minLength.d.ts +1 -0
- package/utils/rules/minLength/minLength.es6.js +16 -0
- package/utils/rules/minLength/minLength.js +20 -0
- package/utils/rules/nullable/index.d.ts +1 -0
- package/utils/rules/nullable/index.es6.js +1 -0
- package/utils/rules/nullable/index.js +9 -0
- package/utils/rules/nullable/nullable.d.ts +1 -0
- package/utils/rules/nullable/nullable.es6.js +10 -0
- package/utils/rules/nullable/nullable.js +14 -0
- package/utils/rules/num/index.d.ts +1 -0
- package/utils/rules/num/index.es6.js +1 -0
- package/utils/rules/num/index.js +9 -0
- package/utils/rules/num/num.d.ts +1 -0
- package/utils/rules/num/num.es6.js +11 -0
- package/utils/rules/num/num.js +15 -0
- package/utils/rules/objectOf/index.d.ts +1 -0
- package/utils/rules/objectOf/index.es6.js +1 -0
- package/utils/rules/objectOf/index.js +9 -0
- package/utils/rules/objectOf/objectOf.d.ts +3 -0
- package/utils/rules/objectOf/objectOf.es6.js +16 -0
- package/utils/rules/objectOf/objectOf.js +20 -0
- package/utils/rules/oneOf/index.d.ts +1 -0
- package/utils/rules/oneOf/index.es6.js +1 -0
- package/utils/rules/oneOf/index.js +9 -0
- package/utils/rules/oneOf/oneOf.d.ts +2 -0
- package/utils/rules/oneOf/oneOf.es6.js +18 -0
- package/utils/rules/oneOf/oneOf.js +22 -0
- package/utils/rules/optional/index.d.ts +1 -0
- package/utils/rules/optional/index.es6.js +1 -0
- package/utils/rules/optional/index.js +9 -0
- package/utils/rules/optional/optional.d.ts +2 -0
- package/utils/rules/optional/optional.es6.js +9 -0
- package/utils/rules/optional/optional.js +13 -0
- package/utils/rules/pattern/index.d.ts +1 -0
- package/utils/rules/pattern/index.es6.js +1 -0
- package/utils/rules/pattern/index.js +9 -0
- package/utils/rules/pattern/pattern.d.ts +1 -0
- package/utils/rules/pattern/pattern.es6.js +13 -0
- package/utils/rules/pattern/pattern.js +17 -0
- package/utils/rules/pipe/index.d.ts +1 -0
- package/utils/rules/pipe/index.es6.js +1 -0
- package/utils/rules/pipe/index.js +9 -0
- package/utils/rules/pipe/pipe.d.ts +2 -0
- package/utils/rules/pipe/pipe.es6.js +7 -0
- package/utils/rules/pipe/pipe.js +11 -0
- package/utils/rules/required/index.d.ts +1 -0
- package/utils/rules/required/index.es6.js +1 -0
- package/utils/rules/required/index.js +9 -0
- package/utils/rules/required/required.d.ts +2 -0
- package/utils/rules/required/required.es6.js +12 -0
- package/utils/rules/required/required.js +16 -0
- package/utils/rules/tupleOf/index.d.ts +1 -0
- package/utils/rules/tupleOf/index.es6.js +1 -0
- package/utils/rules/tupleOf/index.js +9 -0
- package/utils/rules/tupleOf/tupleOf.d.ts +2 -0
- package/utils/rules/tupleOf/tupleOf.es6.js +19 -0
- package/utils/rules/tupleOf/tupleOf.js +23 -0
- package/utils/rules/types.d.ts +4 -0
- package/utils/rules/types.es6.js +1 -0
- package/utils/rules/types.js +2 -0
- package/utils/rules/uuidTo/index.d.ts +1 -0
- package/utils/rules/uuidTo/index.es6.js +1 -0
- package/utils/rules/uuidTo/index.js +9 -0
- package/utils/rules/uuidTo/uuidTo.d.ts +1 -0
- package/utils/rules/uuidTo/uuidTo.es6.js +11 -0
- package/utils/rules/uuidTo/uuidTo.js +15 -0
- package/utils/rules/values/index.d.ts +1 -0
- package/utils/rules/values/index.es6.js +1 -0
- package/utils/rules/values/index.js +9 -0
- package/utils/rules/values/values.d.ts +1 -0
- package/utils/rules/values/values.es6.js +13 -0
- package/utils/rules/values/values.js +17 -0
- package/utils/stringifySearch/index.d.ts +1 -1
- package/utils/stringifySearch/stringifySearch.d.ts +2 -2
- package/utils/stringifySearch/stringifySearch.es6.js +2 -2
- package/utils/stringifySearch/stringifySearch.js +2 -3
- package/experimental/serverFn/serverFn.d.ts +0 -2
- package/experimental/serverFn/serverFn.es6.js +0 -12
- package/hooks/useFiles/index.d.ts +0 -1
- package/hooks/useFiles/index.es6.js +0 -1
- package/hooks/useFiles/useFiles.d.ts +0 -1
- package/hooks/useFiles/useFiles.es6.js +0 -7
- package/plugins/access/access.d.ts +0 -14
- package/plugins/access/access.es6.js +0 -24
- package/plugins/access/access.js +0 -34
- package/plugins/access/index.d.ts +0 -1
- package/plugins/access/index.es6.js +0 -1
- package/plugins/access/index.js +0 -10
- package/plugins/action/action.d.ts +0 -10
- package/plugins/action/action.es6.js +0 -38
- package/plugins/action/action.js +0 -60
- package/plugins/action/index.d.ts +0 -1
- package/plugins/action/index.es6.js +0 -1
- package/plugins/cms/cms.d.ts +0 -9
- package/plugins/cms/cms.es6.js +0 -25
- package/plugins/cms/cms.js +0 -34
- package/plugins/cookie/cookie.d.ts +0 -14
- package/plugins/cookie/cookie.es6.js +0 -21
- package/plugins/cookie/cookie.js +0 -29
- package/plugins/file/file.d.ts +0 -7
- package/plugins/file/file.es6.js +0 -39
- package/plugins/file/file.js +0 -50
- package/plugins/formatter/formatter.d.ts +0 -16
- package/plugins/formatter/formatter.es6.js +0 -30
- package/plugins/formatter/formatter.js +0 -51
- package/plugins/formatter/index.d.ts +0 -1
- package/plugins/formatter/index.es6.js +0 -1
- package/plugins/formatter/index.js +0 -9
- package/plugins/header/header.d.ts +0 -12
- package/plugins/header/header.es6.js +0 -14
- package/plugins/header/header.js +0 -23
- package/plugins/parseBody/parseBody.d.ts +0 -7
- package/plugins/parseBody/parseBody.es6.js +0 -9
- package/plugins/parseBody/parseBody.js +0 -18
- package/plugins/proxy/index.es6.js +0 -1
- package/plugins/proxy/proxy.d.ts +0 -9
- package/plugins/proxy/proxy.es6.js +0 -18
- package/plugins/proxy/proxy.js +0 -28
- package/plugins/redirect/redirect.es6.js +0 -34
- package/plugins/redirect/redirect.js +0 -40
- package/plugins/router/index.d.ts +0 -1
- package/plugins/router/index.es6.js +0 -1
- package/plugins/router/index.js +0 -12
- package/plugins/router/router.d.ts +0 -20
- package/plugins/router/router.es6.js +0 -51
- package/plugins/router/router.js +0 -63
- package/plugins/server/server.d.ts +0 -22
- package/plugins/server/server.es6.js +0 -43
- package/plugins/server/server.js +0 -55
- package/plugins/success/success.es6.js +0 -34
- package/plugins/success/success.js +0 -44
- package/plugins/validation/index.d.ts +0 -1
- package/plugins/validation/index.es6.js +0 -1
- package/plugins/validation/index.js +0 -10
- package/plugins/validation/validation.d.ts +0 -16
- package/plugins/validation/validation.es6.js +0 -31
- package/plugins/validation/validation.js +0 -41
- package/utils/action/Action/Action.d.ts +0 -48
- package/utils/action/Action/Action.es6.js +0 -134
- package/utils/action/Action/Action.js +0 -165
- package/utils/action/Action/index.d.ts +0 -1
- package/utils/action/Action/index.es6.js +0 -1
- package/utils/action/Action/index.js +0 -12
- /package/{experimental → plugins/handler}/serverFn/index.es6.js +0 -0
- /package/{experimental → plugins/handler}/serverFn/index.js +0 -0
- /package/plugins/{server → main/server}/index.es6.js +0 -0
- /package/plugins/{server → main/server}/index.js +0 -0
- /package/plugins/{cms → request/cms}/index.es6.js +0 -0
- /package/plugins/{cms → request/cms}/index.js +0 -0
- /package/plugins/{cookie → request/cookie}/index.es6.js +0 -0
- /package/plugins/{cookie → request/cookie}/index.js +0 -0
- /package/plugins/{error → request/error}/index.es6.js +0 -0
- /package/plugins/{error → request/error}/index.js +0 -0
- /package/plugins/{file → request/file}/index.es6.js +0 -0
- /package/plugins/{file → request/file}/index.js +0 -0
- /package/plugins/{header → request/header}/index.es6.js +0 -0
- /package/plugins/{header → request/header}/index.js +0 -0
- /package/plugins/{redirect → request/redirect}/index.es6.js +0 -0
- /package/plugins/{redirect → request/redirect}/index.js +0 -0
- /package/plugins/{success → request/success}/index.es6.js +0 -0
- /package/plugins/{success → request/success}/index.js +0 -0
- /package/{plugins → utils}/parseBody/index.es6.js +0 -0
- /package/{plugins → utils}/parseBody/index.js +0 -0
package/README.md
CHANGED
|
@@ -13,899 +13,3488 @@
|
|
|
13
13
|
[](https://github.com/d8corp/innet-server/blob/main/LICENSE)
|
|
14
14
|
|
|
15
15
|
## Abstract
|
|
16
|
-
This package helps to create server-side application.
|
|
16
|
+
This package helps to create server-side application based on [innet](https://www.npmjs.com/package/innet).
|
|
17
17
|
|
|
18
|
-
Here you find **JSX components on back-end side** 🎉,
|
|
18
|
+
Here you find **JSX components on back-end side** 🎉, Open API generation, Swagger UI in the box, validation, formatting, cms, proxy and more.
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
You can create Open API documentation without implementation.
|
|
21
|
+
It helps to define API contracts before start implementing on backend and frontend sides.
|
|
21
22
|
|
|
22
23
|
[](https://github.com/d8corp/innet-server/stargazers)
|
|
23
24
|
[](https://github.com/d8corp/innet-server/watchers)
|
|
24
25
|
|
|
26
|
+
## Index
|
|
27
|
+
|
|
28
|
+
[Install](#install)
|
|
29
|
+
[Handler](#handler)
|
|
30
|
+
[Usage](#usage)
|
|
31
|
+
|
|
32
|
+
JSX Elements
|
|
33
|
+
[Main](#main)
|
|
34
|
+
[Utils](#utils)
|
|
35
|
+
[API Info](#api-info)
|
|
36
|
+
[Endpoints](#endpoints)
|
|
37
|
+
[Primitive Data](#primitive-data)
|
|
38
|
+
[List of Data](#list-of-data)
|
|
39
|
+
[Run-Time](#run-time)
|
|
40
|
+
|
|
41
|
+
Customize
|
|
42
|
+
[Components](#components)
|
|
43
|
+
[Hooks](#hooks)
|
|
44
|
+
|
|
25
45
|
## Install
|
|
26
|
-
The simplest way is using `innetjs`
|
|
27
46
|
|
|
28
|
-
|
|
29
|
-
|
|
47
|
+
[← back](#index)
|
|
48
|
+
|
|
49
|
+
The simplest way to start working with `@innet/server`, it is `innetjs` usage.
|
|
50
|
+
|
|
51
|
+
```shell
|
|
52
|
+
npx innetjs init my-app -t api
|
|
53
|
+
```
|
|
54
|
+
*change my-app to work folder name*
|
|
55
|
+
|
|
56
|
+
Go into `my-app` and check `README.md`
|
|
57
|
+
|
|
58
|
+
## Handler
|
|
59
|
+
|
|
60
|
+
[← back](#index)
|
|
61
|
+
|
|
62
|
+
Use `server` handler to start an application.
|
|
63
|
+
|
|
64
|
+
*src/index.ts*
|
|
65
|
+
```typescript
|
|
66
|
+
import innet from 'innet'
|
|
67
|
+
import server from '@innet/server'
|
|
68
|
+
|
|
69
|
+
import app from './app'
|
|
70
|
+
|
|
71
|
+
innet(app, server)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
[← back](#index)
|
|
77
|
+
|
|
78
|
+
Here is a **Hello World** example:
|
|
79
|
+
|
|
80
|
+
*src/app.tsx*
|
|
81
|
+
```typescript jsx
|
|
82
|
+
export default (
|
|
83
|
+
<server>
|
|
84
|
+
<api />
|
|
85
|
+
</server>
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
*Use `npm start` to run this server.*
|
|
90
|
+
|
|
91
|
+
Open http://localhost:80
|
|
92
|
+
You will see a base Open API JSON structure.
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"openapi": "3.1.0",
|
|
97
|
+
"info": {
|
|
98
|
+
"title": "",
|
|
99
|
+
"version": "0.0.0"
|
|
100
|
+
},
|
|
101
|
+
"paths": {}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Main
|
|
106
|
+
|
|
107
|
+
[← back](#index)
|
|
108
|
+
|
|
109
|
+
[\<server>](#server)
|
|
110
|
+
[\<api>](#api)
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
### \<server>
|
|
115
|
+
|
|
116
|
+
[← back](#main)
|
|
117
|
+
|
|
118
|
+
`<server>` element helps to start http(s) server.
|
|
119
|
+
|
|
120
|
+
*src/app.tsx*
|
|
121
|
+
```typescript jsx
|
|
122
|
+
export default (
|
|
123
|
+
<server />
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### port
|
|
128
|
+
|
|
129
|
+
Use `port` property to set up the server port:
|
|
130
|
+
|
|
131
|
+
*src/app.tsx*
|
|
132
|
+
```typescript jsx
|
|
133
|
+
export default (
|
|
134
|
+
<server port={3000} />
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- By default, it uses port `80` for `http` and port `442` for `https`.
|
|
139
|
+
- You can use `PORT` environment variable to set it up on CI level.
|
|
140
|
+
- [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `PORT` in `.env` file of local environment.
|
|
141
|
+
|
|
142
|
+
#### ssl
|
|
143
|
+
|
|
144
|
+
To start `https` server, use `ssl` property:
|
|
145
|
+
|
|
146
|
+
*src/app.tsx*
|
|
147
|
+
```typescript jsx
|
|
148
|
+
export default (
|
|
149
|
+
<server
|
|
150
|
+
ssl={{
|
|
151
|
+
cert: 'url_to_file.crt',
|
|
152
|
+
key: 'url_to_file.key',
|
|
153
|
+
}}
|
|
154
|
+
/>
|
|
155
|
+
)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
- You can use `SSL_KEY` and `SSL_CRT` environment variables to set it up on CI level.
|
|
159
|
+
- [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `SSL_KEY` and `SSL_CRT` in `.env` file.
|
|
160
|
+
- You can add `localhost.key` and `localhost.crt` files in your project folder.
|
|
161
|
+
|
|
162
|
+
#### onStart
|
|
163
|
+
|
|
164
|
+
Use `onStart` prop to handle server start event.
|
|
165
|
+
You can put `httpOnStart` to the prop.
|
|
166
|
+
This will log URL into console after start the server.
|
|
167
|
+
The URL opens the server app.
|
|
168
|
+
|
|
169
|
+
*src/app.tsx*
|
|
170
|
+
```typescript jsx
|
|
171
|
+
import { httpOnStart } from '@innet/server'
|
|
172
|
+
|
|
173
|
+
export default (
|
|
174
|
+
<server
|
|
175
|
+
onStart={httpOnStart}
|
|
176
|
+
/>
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### onRequest
|
|
181
|
+
|
|
182
|
+
Use `onRequest` to handle any request of the server.
|
|
183
|
+
|
|
184
|
+
*src/app.tsx*
|
|
185
|
+
```typescript jsx
|
|
186
|
+
export default (
|
|
187
|
+
<server
|
|
188
|
+
onRequest={(req, res) => console.log({
|
|
189
|
+
req,
|
|
190
|
+
res,
|
|
191
|
+
})}
|
|
192
|
+
/>
|
|
193
|
+
)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### onError
|
|
197
|
+
|
|
198
|
+
Use `onError` to handle any request error on the server.
|
|
199
|
+
|
|
200
|
+
*src/app.tsx*
|
|
201
|
+
```typescript jsx
|
|
202
|
+
export default (
|
|
203
|
+
<server
|
|
204
|
+
onError={error => console.error(error)}
|
|
205
|
+
/>
|
|
206
|
+
)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### \<api>
|
|
210
|
+
|
|
211
|
+
[← back](#main)
|
|
212
|
+
|
|
213
|
+
`<api>` element MUST be placed in `<server>` element.
|
|
214
|
+
This element defines a REST API on the server.
|
|
215
|
+
|
|
216
|
+
#### title
|
|
217
|
+
|
|
218
|
+
This is a title of the API.
|
|
219
|
+
Open API specifies the parameter is REQUIRED.
|
|
220
|
+
But it's NOT REQUIRED in `<api>` element, it equals [empty string](#usage) by default.
|
|
221
|
+
|
|
222
|
+
*src/app.tsx*
|
|
223
|
+
```typescript jsx
|
|
224
|
+
export default (
|
|
225
|
+
<server>
|
|
226
|
+
<api
|
|
227
|
+
title='@innet/server API'
|
|
228
|
+
/>
|
|
229
|
+
</server>
|
|
230
|
+
)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### description
|
|
234
|
+
|
|
235
|
+
You can add a `description` of the API.
|
|
236
|
+
[CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
237
|
+
|
|
238
|
+
*src/app.tsx*
|
|
239
|
+
```typescript jsx
|
|
240
|
+
export default (
|
|
241
|
+
<server>
|
|
242
|
+
<api
|
|
243
|
+
description='**MARKDOWN** is available'
|
|
244
|
+
/>
|
|
245
|
+
</server>
|
|
246
|
+
)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
[innetjs](https://www.npmjs.com/package/innetjs) can help to use a separate file of description:
|
|
250
|
+
|
|
251
|
+
*src/app.tsx*
|
|
252
|
+
```typescript jsx
|
|
253
|
+
import desc from './desc.md'
|
|
254
|
+
|
|
255
|
+
export default (
|
|
256
|
+
<server>
|
|
257
|
+
<api description={desc} />
|
|
258
|
+
</server>
|
|
259
|
+
)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
#### summary
|
|
263
|
+
|
|
264
|
+
Add a short summary of the API.
|
|
265
|
+
|
|
266
|
+
*src/app.tsx*
|
|
267
|
+
```typescript jsx
|
|
268
|
+
export default (
|
|
269
|
+
<server>
|
|
270
|
+
<api
|
|
271
|
+
summary='Hello World!'
|
|
272
|
+
/>
|
|
273
|
+
</server>
|
|
274
|
+
)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### version
|
|
278
|
+
|
|
279
|
+
The version of the OpenAPI document (which is distinct from the
|
|
280
|
+
[OpenAPI Specification version](https://swagger.io/specification/#oas-version)
|
|
281
|
+
or the API implementation version).
|
|
282
|
+
|
|
283
|
+
*src/app.tsx*
|
|
284
|
+
```typescript jsx
|
|
285
|
+
export default (
|
|
286
|
+
<server>
|
|
287
|
+
<api
|
|
288
|
+
title='@innet/server API'
|
|
289
|
+
version='1.0.1'
|
|
290
|
+
/>
|
|
291
|
+
</server>
|
|
292
|
+
)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
*default: 0.0.0*
|
|
296
|
+
|
|
297
|
+
#### prefix
|
|
298
|
+
|
|
299
|
+
URL path prefix scopes the API.
|
|
300
|
+
|
|
301
|
+
*src/app.tsx*
|
|
302
|
+
```typescript jsx
|
|
303
|
+
export default (
|
|
304
|
+
<server>
|
|
305
|
+
<api
|
|
306
|
+
prefix='/api'
|
|
307
|
+
/>
|
|
308
|
+
</server>
|
|
309
|
+
)
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Utils
|
|
313
|
+
|
|
314
|
+
This section contains elements of utils.
|
|
315
|
+
|
|
316
|
+
[← back](#index)
|
|
317
|
+
|
|
318
|
+
[\<swagger>](#swagger)
|
|
319
|
+
[\<dev>](#dev)
|
|
320
|
+
[\<dts>](#dts)
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
### \<swagger>
|
|
325
|
+
|
|
326
|
+
[← back](#utils)
|
|
327
|
+
|
|
328
|
+
Use `<swagger>` element to add Swagger UI documentation.
|
|
329
|
+
`<swagger>` element MUST be placed in `<api>` element.
|
|
330
|
+
|
|
331
|
+
*src/app.tsx*
|
|
332
|
+
```typescript jsx
|
|
333
|
+
export default (
|
|
334
|
+
<server>
|
|
335
|
+
<api>
|
|
336
|
+
<swagger />
|
|
337
|
+
</api>
|
|
338
|
+
</server>
|
|
339
|
+
)
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Open http://localhost:80/swagger-ui
|
|
343
|
+
You will see Swagger UI documentation.
|
|
344
|
+
|
|
345
|
+
You can change the Swagger UI URL path by `path` property of `<swagger>` element.
|
|
346
|
+
|
|
347
|
+
*src/app.tsx*
|
|
348
|
+
```typescript jsx
|
|
349
|
+
export default (
|
|
350
|
+
<server>
|
|
351
|
+
<api>
|
|
352
|
+
<swagger path='/swagger' />
|
|
353
|
+
</api>
|
|
354
|
+
</server>
|
|
355
|
+
)
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### \<dev>
|
|
359
|
+
|
|
360
|
+
[← back](#utils)
|
|
361
|
+
|
|
362
|
+
Everything inside <dev> will work when `NODE_ENV` equals `development`.
|
|
363
|
+
|
|
364
|
+
*src/app.tsx*
|
|
365
|
+
```typescript jsx
|
|
366
|
+
export default (
|
|
367
|
+
<server>
|
|
368
|
+
<api>
|
|
369
|
+
<dev>
|
|
370
|
+
<swagger />
|
|
371
|
+
</dev>
|
|
372
|
+
</api>
|
|
373
|
+
</server>
|
|
374
|
+
)
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### \<dts>
|
|
378
|
+
|
|
379
|
+
[← back](#utils)
|
|
380
|
+
|
|
381
|
+
Use `<dts>` element to add types generation.
|
|
382
|
+
`<dts>` element MUST be placed in `<api>` element.
|
|
383
|
+
|
|
384
|
+
`<dts>` has a required prop of `path`. This is a path of api TypeScript types file, `<dts>` generates it.
|
|
385
|
+
|
|
386
|
+
*src/app.tsx*
|
|
387
|
+
```typescript jsx
|
|
388
|
+
export default (
|
|
389
|
+
<server>
|
|
390
|
+
<api>
|
|
391
|
+
<dev>
|
|
392
|
+
<dts path='src/api.d.ts' />
|
|
393
|
+
</dev>
|
|
394
|
+
</api>
|
|
395
|
+
</server>
|
|
396
|
+
)
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
> You MUST add some [endpoint](#endpoint) with some schema otherwise you get the `Error: There is no schema in the input contents`.
|
|
400
|
+
|
|
401
|
+
Here is an example of generated types usage.
|
|
402
|
+
|
|
403
|
+
*src/GetPartner.tsx*
|
|
404
|
+
```typescript jsx
|
|
405
|
+
import { useParams } from '@innet/server'
|
|
406
|
+
|
|
407
|
+
export function GetPartner () {
|
|
408
|
+
const { id } = useParams<Paths.Partners$Id.Get.PathParameters>()
|
|
409
|
+
return <success>{{ id }}</success>
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
You do not need to import types, they generate as namespaces.
|
|
414
|
+
|
|
415
|
+
## API Info
|
|
416
|
+
|
|
417
|
+
The API information elements are here.
|
|
418
|
+
|
|
419
|
+
[← back](#index)
|
|
420
|
+
|
|
421
|
+
[\<license>](#license)
|
|
422
|
+
[\<contact>](#contact)
|
|
423
|
+
[\<host>](#host)
|
|
424
|
+
[\<variable>](#variable)
|
|
425
|
+
|
|
426
|
+
---
|
|
427
|
+
|
|
428
|
+
### \<license>
|
|
429
|
+
|
|
430
|
+
[← back](#api-info)
|
|
431
|
+
|
|
432
|
+
`<license>` element MUST be placed in `<api>` element.
|
|
433
|
+
Use `<license>` element to define the API license.
|
|
434
|
+
|
|
435
|
+
#### name
|
|
436
|
+
|
|
437
|
+
REQUIRED prop. The license name used for the API.
|
|
438
|
+
|
|
439
|
+
*src/app.tsx*
|
|
440
|
+
```typescript jsx
|
|
441
|
+
export default (
|
|
442
|
+
<server>
|
|
443
|
+
<api>
|
|
444
|
+
<license
|
|
445
|
+
name='Apache 2.0'
|
|
446
|
+
/>
|
|
447
|
+
</api>
|
|
448
|
+
</server>
|
|
449
|
+
)
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
#### identifier
|
|
453
|
+
|
|
454
|
+
An [SPDX](https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60) license expression for the API.
|
|
455
|
+
The `identifier` field is mutually exclusive of the `url` prop.
|
|
456
|
+
|
|
457
|
+
*src/app.tsx*
|
|
458
|
+
```typescript jsx
|
|
459
|
+
export default (
|
|
460
|
+
<server>
|
|
461
|
+
<api>
|
|
462
|
+
<license
|
|
463
|
+
name='Apache 2.0'
|
|
464
|
+
identifier='Apache-2.0'
|
|
465
|
+
/>
|
|
466
|
+
</api>
|
|
467
|
+
</server>
|
|
468
|
+
)
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
#### url
|
|
472
|
+
|
|
473
|
+
A URL to the license used for the API.
|
|
474
|
+
This MUST be in the form of a URL.
|
|
475
|
+
The `url` field is mutually exclusive of the `identifier` field.
|
|
476
|
+
|
|
477
|
+
*src/app.tsx*
|
|
478
|
+
```typescript jsx
|
|
479
|
+
export default (
|
|
480
|
+
<server>
|
|
481
|
+
<api>
|
|
482
|
+
<license
|
|
483
|
+
name='Apache 2.0'
|
|
484
|
+
url='https://www.apache.org/licenses/LICENSE-2.0.html'
|
|
485
|
+
/>
|
|
486
|
+
</api>
|
|
487
|
+
</server>
|
|
488
|
+
)
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### \<contact>
|
|
492
|
+
|
|
493
|
+
[← back](#api-info)
|
|
494
|
+
|
|
495
|
+
`<contact>` element MUST be placed in `<api>` element.
|
|
496
|
+
The contact information for the exposed API.
|
|
497
|
+
|
|
498
|
+
#### name
|
|
499
|
+
|
|
500
|
+
The identifying name of the contact person/organization.
|
|
501
|
+
|
|
502
|
+
*src/app.tsx*
|
|
503
|
+
```typescript jsx
|
|
504
|
+
export default (
|
|
505
|
+
<server>
|
|
506
|
+
<api>
|
|
507
|
+
<contact name='Mike' />
|
|
508
|
+
</api>
|
|
509
|
+
</server>
|
|
510
|
+
)
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
#### email
|
|
514
|
+
|
|
515
|
+
The email address of the contact person/organization.
|
|
516
|
+
This MUST be in the form of an email address.
|
|
517
|
+
|
|
518
|
+
*src/app.tsx*
|
|
519
|
+
```typescript jsx
|
|
520
|
+
export default (
|
|
521
|
+
<server>
|
|
522
|
+
<api>
|
|
523
|
+
<contact
|
|
524
|
+
email='d8@cantinc.com'
|
|
525
|
+
/>
|
|
526
|
+
</api>
|
|
527
|
+
</server>
|
|
528
|
+
)
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
#### url
|
|
532
|
+
|
|
533
|
+
The URL pointing to the contact information.
|
|
534
|
+
This MUST be in the form of a URL.
|
|
535
|
+
|
|
536
|
+
*src/app.tsx*
|
|
537
|
+
```typescript jsx
|
|
538
|
+
export default (
|
|
539
|
+
<server>
|
|
540
|
+
<api>
|
|
541
|
+
<contact
|
|
542
|
+
url='https://...'
|
|
543
|
+
/>
|
|
544
|
+
</api>
|
|
545
|
+
</server>
|
|
546
|
+
)
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
### \<host>
|
|
550
|
+
|
|
551
|
+
[← back](#api-info)
|
|
552
|
+
|
|
553
|
+
`<host>` element MUST be placed in `<api>` element.
|
|
554
|
+
|
|
555
|
+
This element adds a link to related documentation API.
|
|
556
|
+
You can provide many stands like dev, stage or prod.
|
|
557
|
+
|
|
558
|
+
#### url
|
|
559
|
+
|
|
560
|
+
REQUIRED prop of URL to the target host.
|
|
561
|
+
|
|
562
|
+
This URL supports Server Variables and MAY be relative,
|
|
563
|
+
to indicate that the host location is relative to the location where the OpenAPI document is being served.
|
|
564
|
+
Variable substitutions will be made when a variable is named in {brackets}.
|
|
565
|
+
|
|
566
|
+
*src/app.tsx*
|
|
567
|
+
```typescript jsx
|
|
568
|
+
export default (
|
|
569
|
+
<server>
|
|
570
|
+
<api>
|
|
571
|
+
<host
|
|
572
|
+
url='https://your.address/api'
|
|
573
|
+
/>
|
|
574
|
+
</api>
|
|
575
|
+
</server>
|
|
576
|
+
)
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
#### description
|
|
580
|
+
|
|
581
|
+
An optional string describing the host designated by the URL.
|
|
582
|
+
[CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
|
|
583
|
+
|
|
584
|
+
*src/app.tsx*
|
|
585
|
+
```typescript jsx
|
|
586
|
+
export default (
|
|
587
|
+
<server>
|
|
588
|
+
<api>
|
|
589
|
+
<host
|
|
590
|
+
url='https://your.address/api'
|
|
591
|
+
description='Production server'
|
|
592
|
+
/>
|
|
593
|
+
</api>
|
|
594
|
+
</server>
|
|
595
|
+
)
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
### \<variable>
|
|
599
|
+
|
|
600
|
+
[← back](#api-info)
|
|
601
|
+
|
|
602
|
+
This element MUST be placed in `<host>` element and defines a variable from the `<host>`.
|
|
603
|
+
|
|
604
|
+
#### key
|
|
605
|
+
|
|
606
|
+
REQUIRED props. `key` is a server url parameter.
|
|
607
|
+
|
|
608
|
+
*src/app.tsx*
|
|
609
|
+
```typescript jsx
|
|
610
|
+
export default (
|
|
611
|
+
<server>
|
|
612
|
+
<api>
|
|
613
|
+
<host
|
|
614
|
+
url='https://{env}.your.address/api'
|
|
615
|
+
description='Test servers'>
|
|
616
|
+
<variable key='env' />
|
|
617
|
+
</host>
|
|
618
|
+
</api>
|
|
619
|
+
</server>
|
|
620
|
+
)
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
#### value
|
|
624
|
+
|
|
625
|
+
The `value` prop uses for substitution by default.
|
|
626
|
+
If the `values` is defined, the `value` MUST exist in the `values`.
|
|
627
|
+
|
|
628
|
+
*src/app.tsx*
|
|
629
|
+
```typescript jsx
|
|
630
|
+
export default (
|
|
631
|
+
<server>
|
|
632
|
+
<api>
|
|
633
|
+
<host
|
|
634
|
+
url='https://{env}.your.address/api'
|
|
635
|
+
description='Test servers'>
|
|
636
|
+
<variable
|
|
637
|
+
key='env'
|
|
638
|
+
value='stage'
|
|
639
|
+
/>
|
|
640
|
+
</host>
|
|
641
|
+
</api>
|
|
642
|
+
</server>
|
|
643
|
+
)
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
#### values
|
|
647
|
+
|
|
648
|
+
An enumeration of string values to be used if the substitution options are from a limited set.
|
|
649
|
+
The array MUST NOT be empty.
|
|
650
|
+
|
|
651
|
+
*src/app.tsx*
|
|
652
|
+
```typescript jsx
|
|
653
|
+
export default (
|
|
654
|
+
<server>
|
|
655
|
+
<api>
|
|
656
|
+
<host
|
|
657
|
+
url='https://{env}.your.address/api'
|
|
658
|
+
description='Test servers'>
|
|
659
|
+
<variable
|
|
660
|
+
key='env'
|
|
661
|
+
values={[
|
|
662
|
+
'stage',
|
|
663
|
+
'dev',
|
|
664
|
+
'qa',
|
|
665
|
+
]}
|
|
666
|
+
/>
|
|
667
|
+
</host>
|
|
668
|
+
</api>
|
|
669
|
+
</server>
|
|
670
|
+
)
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
#### description
|
|
674
|
+
|
|
675
|
+
An optional description for the server variable.
|
|
676
|
+
[CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
677
|
+
|
|
678
|
+
*src/app.tsx*
|
|
679
|
+
```typescript jsx
|
|
680
|
+
export default (
|
|
681
|
+
<server>
|
|
682
|
+
<api>
|
|
683
|
+
<host
|
|
684
|
+
url='https://{env}.your.address/api'
|
|
685
|
+
description='Test servers'>
|
|
686
|
+
<variable
|
|
687
|
+
key='env'
|
|
688
|
+
values={[
|
|
689
|
+
'stage',
|
|
690
|
+
'dev',
|
|
691
|
+
'qa',
|
|
692
|
+
]}
|
|
693
|
+
description='Server environment'
|
|
694
|
+
/>
|
|
695
|
+
</host>
|
|
696
|
+
</api>
|
|
697
|
+
</server>
|
|
698
|
+
)
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
## Endpoints
|
|
702
|
+
|
|
703
|
+
[← back](#index)
|
|
704
|
+
|
|
705
|
+
[\<endpoint>](#endpoint)
|
|
706
|
+
[\<tag>](#tag)
|
|
707
|
+
[\<param>](#param)
|
|
708
|
+
[\<body>](#body)
|
|
709
|
+
[\<response>](#response)
|
|
710
|
+
|
|
711
|
+
---
|
|
712
|
+
|
|
713
|
+
### \<endpoint>
|
|
714
|
+
|
|
715
|
+
[← back](#endpoints)
|
|
716
|
+
|
|
717
|
+
`<endpoint>` defines an endpoint of the API and MUST be placed in `<api>`.
|
|
718
|
+
|
|
719
|
+
`<api>` uses a specific algorithm to find expected endpoint.
|
|
720
|
+
|
|
721
|
+
It does no matter how many endpoints you have.
|
|
722
|
+
It depends on the deep of path pieces.
|
|
723
|
+
If you have the deep equals 1 (`/users`, `/user`, `/login`, `/logout`) the endpoint will be found immediately O(1).
|
|
724
|
+
|
|
725
|
+
#### method
|
|
726
|
+
|
|
727
|
+
A method of the endpoint.
|
|
728
|
+
|
|
729
|
+
MUST be one of `'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'head' | 'trace'`
|
|
730
|
+
|
|
731
|
+
#### path
|
|
732
|
+
|
|
733
|
+
A relative path to an individual endpoint.
|
|
734
|
+
|
|
735
|
+
The property MUST begin with a forward slash (/).
|
|
736
|
+
|
|
737
|
+
Path templating is allowed.
|
|
738
|
+
|
|
739
|
+
When matching URLs, concrete (non-templated) paths would be matched before their templated counterparts.
|
|
740
|
+
Templated paths with the same hierarchy but different templated names MUST NOT exist as they are identical.
|
|
741
|
+
|
|
742
|
+
*src/app.tsx*
|
|
743
|
+
```typescript jsx
|
|
744
|
+
export default (
|
|
745
|
+
<server>
|
|
746
|
+
<api>
|
|
747
|
+
<endpoint
|
|
748
|
+
method='get'
|
|
749
|
+
path='/users'
|
|
750
|
+
/>
|
|
751
|
+
</api>
|
|
752
|
+
</server>
|
|
753
|
+
)
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
#### summary
|
|
757
|
+
|
|
758
|
+
An optional, string summary, intended to apply to all operations in this path.
|
|
759
|
+
|
|
760
|
+
*src/app.tsx*
|
|
761
|
+
```typescript jsx
|
|
762
|
+
export default (
|
|
763
|
+
<server>
|
|
764
|
+
<api>
|
|
765
|
+
<endpoint
|
|
766
|
+
method='get'
|
|
767
|
+
path='/users'
|
|
768
|
+
summary='Returns users'
|
|
769
|
+
/>
|
|
770
|
+
</api>
|
|
771
|
+
</server>
|
|
772
|
+
)
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
#### description
|
|
776
|
+
|
|
777
|
+
An optional, string description, intended to apply to all operations in this path.
|
|
778
|
+
[CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
779
|
+
|
|
780
|
+
*src/app.tsx*
|
|
781
|
+
```typescript jsx
|
|
782
|
+
export default (
|
|
783
|
+
<server>
|
|
784
|
+
<api>
|
|
785
|
+
<endpoint
|
|
786
|
+
method='get'
|
|
787
|
+
path='/users'
|
|
788
|
+
description='Users list query'
|
|
789
|
+
/>
|
|
790
|
+
</api>
|
|
791
|
+
</server>
|
|
792
|
+
)
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
#### deprecated
|
|
796
|
+
|
|
797
|
+
Declares this operation to be deprecated.
|
|
798
|
+
Consumers SHOULD refrain from usage of the declared operation.
|
|
799
|
+
Default value is `false`.
|
|
800
|
+
|
|
801
|
+
*src/app.tsx*
|
|
802
|
+
```typescript jsx
|
|
803
|
+
export default (
|
|
804
|
+
<server>
|
|
805
|
+
<api>
|
|
806
|
+
<endpoint
|
|
807
|
+
method='get'
|
|
808
|
+
path='/users'
|
|
809
|
+
deprecated
|
|
810
|
+
/>
|
|
811
|
+
</api>
|
|
812
|
+
</server>
|
|
813
|
+
)
|
|
814
|
+
```
|
|
815
|
+
|
|
816
|
+
#### private
|
|
817
|
+
|
|
818
|
+
Declares this operation to make an endpoint private.
|
|
819
|
+
That means the endpoint should not be described and will not be shown in the Open API documentation.
|
|
820
|
+
|
|
821
|
+
*src/app.tsx*
|
|
822
|
+
```typescript jsx
|
|
823
|
+
export default (
|
|
824
|
+
<server>
|
|
825
|
+
<api>
|
|
826
|
+
<endpoint
|
|
827
|
+
method='get'
|
|
828
|
+
path='/users'
|
|
829
|
+
private
|
|
830
|
+
/>
|
|
831
|
+
</api>
|
|
832
|
+
</server>
|
|
833
|
+
)
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
### \<tag>
|
|
837
|
+
|
|
838
|
+
[← back](#endpoints)
|
|
839
|
+
|
|
840
|
+
You can wrap endpoints by `<tag>` element to group the endpoints.
|
|
841
|
+
You can see the changes in Swagger UI.
|
|
842
|
+
|
|
843
|
+
*src/app.tsx*
|
|
844
|
+
```typescript jsx
|
|
845
|
+
export default (
|
|
846
|
+
<server>
|
|
847
|
+
<api>
|
|
848
|
+
<tag name='user'>
|
|
849
|
+
<endpoint
|
|
850
|
+
method='get'
|
|
851
|
+
path='/users'
|
|
852
|
+
/>
|
|
853
|
+
<endpoint
|
|
854
|
+
method='post'
|
|
855
|
+
path='/users'
|
|
856
|
+
/>
|
|
857
|
+
</tag>
|
|
858
|
+
</api>
|
|
859
|
+
</server>
|
|
860
|
+
)
|
|
861
|
+
```
|
|
862
|
+
|
|
863
|
+
### \<param>
|
|
864
|
+
|
|
865
|
+
[← back](#endpoints)
|
|
866
|
+
|
|
867
|
+
Describes a single operation parameter.
|
|
868
|
+
|
|
869
|
+
A unique parameter is defined by a combination of a `name` and location.
|
|
870
|
+
|
|
871
|
+
##### Parameter Locations
|
|
872
|
+
|
|
873
|
+
There are four possible parameter locations specified by the `in` prop:
|
|
874
|
+
|
|
875
|
+
- **path** - Used together with [Path Templating](https://swagger.io/specification/#path-templating), where the parameter value is actually part of the operation's URL.
|
|
876
|
+
This does not include the host or base path of the API. For example, in `/items/{itemId}`, the path parameter is `itemId`.
|
|
877
|
+
- **query** - Parameters that are appended to the URL. For example, in `/items?id=###`, the query parameter is `id`.
|
|
878
|
+
- **header** - Custom headers that are expected as part of the request. Note that RFC7230 states header names are case insensitive.
|
|
879
|
+
- **cookie** - Used to pass a specific cookie value to the API.
|
|
880
|
+
|
|
881
|
+
#### in
|
|
882
|
+
|
|
883
|
+
The location of the parameter.
|
|
884
|
+
Possible values are `"query"`, `"header"`, `"path"` or `"cookie"`.
|
|
885
|
+
|
|
886
|
+
#### name
|
|
887
|
+
|
|
888
|
+
The name of the parameter. Parameter names are *case sensitive*.
|
|
889
|
+
|
|
890
|
+
- If `in` is "path", the `name` field MUST correspond to a template expression occurring within the `path` field in the `endpoint`. See [Path Templating](https://swagger.io/specification/#path-templating) for further information.
|
|
891
|
+
- If `in` is "header" and the `name` field is "Accept", "Content-Type" or "Authorization", the parameter definition SHALL be ignored.
|
|
892
|
+
- For all other cases, the `name` corresponds to the parameter name used by the `in` property.
|
|
893
|
+
|
|
894
|
+
*src/app.tsx*
|
|
895
|
+
```typescript jsx
|
|
896
|
+
export default (
|
|
897
|
+
<server>
|
|
898
|
+
<api>
|
|
899
|
+
<endpoint method='get' path='/users/{userId}'>
|
|
900
|
+
<param in='path' name='userId' />
|
|
901
|
+
</endpoint>
|
|
902
|
+
</api>
|
|
903
|
+
</server>
|
|
904
|
+
)
|
|
905
|
+
```
|
|
906
|
+
|
|
907
|
+
#### description
|
|
908
|
+
|
|
909
|
+
A brief description of the parameter.
|
|
910
|
+
This could contain examples of use.
|
|
911
|
+
[CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
912
|
+
|
|
913
|
+
*src/app.tsx*
|
|
914
|
+
```typescript jsx
|
|
915
|
+
export default (
|
|
916
|
+
<server>
|
|
917
|
+
<api>
|
|
918
|
+
<endpoint method='get' path='/users/{userId}'>
|
|
919
|
+
<param
|
|
920
|
+
in='path'
|
|
921
|
+
name='userId'
|
|
922
|
+
description='User identification number'
|
|
923
|
+
/>
|
|
924
|
+
</endpoint>
|
|
925
|
+
</api>
|
|
926
|
+
</server>
|
|
927
|
+
)
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
#### required
|
|
931
|
+
|
|
932
|
+
Determines whether this parameter is mandatory.
|
|
933
|
+
If the parameter location is "path", this property is `true` and its value MUST be `true`.
|
|
934
|
+
Otherwise, the property MAY be included and its default value is `false`.
|
|
935
|
+
|
|
936
|
+
*src/app.tsx*
|
|
937
|
+
```typescript jsx
|
|
938
|
+
export default (
|
|
939
|
+
<server>
|
|
940
|
+
<api>
|
|
941
|
+
<endpoint method='get' path='/users'>
|
|
942
|
+
<param
|
|
943
|
+
in='cookie'
|
|
944
|
+
name='token'
|
|
945
|
+
required
|
|
946
|
+
/>
|
|
947
|
+
</endpoint>
|
|
948
|
+
</api>
|
|
949
|
+
</server>
|
|
950
|
+
)
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
#### deprecated
|
|
954
|
+
|
|
955
|
+
Specifies that a parameter is deprecated and SHOULD be transitioned out of usage.
|
|
956
|
+
Default value is `false`.
|
|
957
|
+
|
|
958
|
+
*src/app.tsx*
|
|
959
|
+
```typescript jsx
|
|
960
|
+
export default (
|
|
961
|
+
<server>
|
|
962
|
+
<api>
|
|
963
|
+
<endpoint method='get' path='/users'>
|
|
964
|
+
<param
|
|
965
|
+
in='query'
|
|
966
|
+
name='status'
|
|
967
|
+
deprecated
|
|
968
|
+
/>
|
|
969
|
+
</endpoint>
|
|
970
|
+
</api>
|
|
971
|
+
</server>
|
|
972
|
+
)
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
### \<body>
|
|
976
|
+
|
|
977
|
+
[← back](#endpoints)
|
|
978
|
+
|
|
979
|
+
This element MUST be placed inside `<endpoint>`.
|
|
980
|
+
It defines request body for the endpoint.
|
|
981
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
982
|
+
|
|
983
|
+
```typescript jsx
|
|
984
|
+
return (
|
|
985
|
+
<server>
|
|
986
|
+
<api>
|
|
987
|
+
<endpoint method='post' path='/partners'>
|
|
988
|
+
<body>
|
|
989
|
+
<object>
|
|
990
|
+
<field key='name'>
|
|
991
|
+
<string example='CANTent.' />
|
|
992
|
+
</field>
|
|
993
|
+
<field key='gift'>
|
|
994
|
+
<boolean />
|
|
995
|
+
</field>
|
|
996
|
+
<field optional key='addresses'>
|
|
997
|
+
<array>
|
|
998
|
+
<number description='address id' />
|
|
999
|
+
</array>
|
|
1000
|
+
</field>
|
|
1001
|
+
</object>
|
|
1002
|
+
</body>
|
|
1003
|
+
</endpoint>
|
|
1004
|
+
</api>
|
|
1005
|
+
</server>
|
|
1006
|
+
)
|
|
1007
|
+
```
|
|
1008
|
+
|
|
1009
|
+
### \<response>
|
|
1010
|
+
|
|
1011
|
+
[← back](#endpoints)
|
|
1012
|
+
|
|
1013
|
+
This element MUST be placed inside `<endpoint>`.
|
|
1014
|
+
It defines response body for the endpoint.
|
|
1015
|
+
|
|
1016
|
+
## Primitive Data
|
|
1017
|
+
|
|
1018
|
+
[← back](#index)
|
|
1019
|
+
|
|
1020
|
+
[\<null>](#null)
|
|
1021
|
+
[\<boolean>](#boolean)
|
|
1022
|
+
[\<string>](#string)
|
|
1023
|
+
[\<number>](#number)
|
|
1024
|
+
[\<integer>](#integer)
|
|
1025
|
+
[\<date>](#date)
|
|
1026
|
+
[\<uuid>](#uuid)
|
|
1027
|
+
[\<binary>](#binary)
|
|
1028
|
+
|
|
1029
|
+
### \<boolean>
|
|
1030
|
+
|
|
1031
|
+
[← back](#primitive-data)
|
|
1032
|
+
|
|
1033
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
1034
|
+
It defines `boolean` value for a parent element.
|
|
1035
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
1036
|
+
|
|
1037
|
+
*src/app.tsx*
|
|
1038
|
+
```typescript jsx
|
|
1039
|
+
export default (
|
|
1040
|
+
<server>
|
|
1041
|
+
<api>
|
|
1042
|
+
<endpoint method='get' path='/users'>
|
|
1043
|
+
<param
|
|
1044
|
+
in='query'
|
|
1045
|
+
name='active'>
|
|
1046
|
+
<boolean />
|
|
1047
|
+
</param>
|
|
1048
|
+
</endpoint>
|
|
1049
|
+
</api>
|
|
1050
|
+
</server>
|
|
1051
|
+
)
|
|
1052
|
+
```
|
|
1053
|
+
|
|
1054
|
+
#### default
|
|
1055
|
+
|
|
1056
|
+
A default value for the `boolean`.
|
|
1057
|
+
|
|
1058
|
+
*src/app.tsx*
|
|
1059
|
+
```typescript jsx
|
|
1060
|
+
export default (
|
|
1061
|
+
<server>
|
|
1062
|
+
<api>
|
|
1063
|
+
<endpoint method='get' path='/users'>
|
|
1064
|
+
<param
|
|
1065
|
+
in='query'
|
|
1066
|
+
name='active'>
|
|
1067
|
+
<boolean default={false} />
|
|
1068
|
+
</param>
|
|
1069
|
+
</endpoint>
|
|
1070
|
+
</api>
|
|
1071
|
+
</server>
|
|
1072
|
+
)
|
|
1073
|
+
```
|
|
1074
|
+
|
|
1075
|
+
#### example
|
|
1076
|
+
|
|
1077
|
+
An example value.
|
|
1078
|
+
|
|
1079
|
+
*src/app.tsx*
|
|
1080
|
+
```typescript jsx
|
|
1081
|
+
export default (
|
|
1082
|
+
<server>
|
|
1083
|
+
<api>
|
|
1084
|
+
<endpoint method='get' path='/products'>
|
|
1085
|
+
<param
|
|
1086
|
+
in='query'
|
|
1087
|
+
name='active'>
|
|
1088
|
+
<boolean example={false} />
|
|
1089
|
+
</param>
|
|
1090
|
+
</endpoint>
|
|
1091
|
+
</api>
|
|
1092
|
+
</server>
|
|
1093
|
+
)
|
|
1094
|
+
```
|
|
1095
|
+
|
|
1096
|
+
#### description
|
|
1097
|
+
|
|
1098
|
+
A description of the `boolean`.
|
|
1099
|
+
|
|
1100
|
+
*src/app.tsx*
|
|
1101
|
+
```typescript jsx
|
|
1102
|
+
export default (
|
|
1103
|
+
<server>
|
|
1104
|
+
<api>
|
|
1105
|
+
<endpoint method='get' path='/products'>
|
|
1106
|
+
<param
|
|
1107
|
+
in='query'
|
|
1108
|
+
name='active'>
|
|
1109
|
+
<boolean
|
|
1110
|
+
description='Active products param'
|
|
1111
|
+
/>
|
|
1112
|
+
</param>
|
|
1113
|
+
</endpoint>
|
|
1114
|
+
</api>
|
|
1115
|
+
</server>
|
|
1116
|
+
)
|
|
1117
|
+
```
|
|
1118
|
+
|
|
1119
|
+
### \<string>
|
|
1120
|
+
|
|
1121
|
+
[← back](#primitive-data)
|
|
1122
|
+
|
|
1123
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
1124
|
+
It defines `string` value for a parent element.
|
|
1125
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
1126
|
+
|
|
1127
|
+
*src/app.tsx*
|
|
1128
|
+
```typescript jsx
|
|
1129
|
+
export default (
|
|
1130
|
+
<server>
|
|
1131
|
+
<api>
|
|
1132
|
+
<endpoint method='get' path='/users'>
|
|
1133
|
+
<param
|
|
1134
|
+
in='query'
|
|
1135
|
+
name='search'>
|
|
1136
|
+
<string />
|
|
1137
|
+
</param>
|
|
1138
|
+
</endpoint>
|
|
1139
|
+
</api>
|
|
1140
|
+
</server>
|
|
1141
|
+
)
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
#### default
|
|
1145
|
+
|
|
1146
|
+
A default value for the `string`.
|
|
1147
|
+
|
|
1148
|
+
*src/app.tsx*
|
|
1149
|
+
```typescript jsx
|
|
1150
|
+
export default (
|
|
1151
|
+
<server>
|
|
1152
|
+
<api>
|
|
1153
|
+
<endpoint method='get' path='/users'>
|
|
1154
|
+
<param
|
|
1155
|
+
in='query'
|
|
1156
|
+
name='status'>
|
|
1157
|
+
<string default='active' />
|
|
1158
|
+
</param>
|
|
1159
|
+
</endpoint>
|
|
1160
|
+
</api>
|
|
1161
|
+
</server>
|
|
1162
|
+
)
|
|
1163
|
+
```
|
|
1164
|
+
|
|
1165
|
+
*By default, `status` query param equals `active`*
|
|
1166
|
+
|
|
1167
|
+
#### example
|
|
1168
|
+
|
|
1169
|
+
An example value.
|
|
1170
|
+
|
|
1171
|
+
*src/app.tsx*
|
|
1172
|
+
```typescript jsx
|
|
1173
|
+
export default (
|
|
1174
|
+
<server>
|
|
1175
|
+
<api>
|
|
1176
|
+
<endpoint method='get' path='/products'>
|
|
1177
|
+
<param
|
|
1178
|
+
in='query'
|
|
1179
|
+
name='search'>
|
|
1180
|
+
<string example='red socks' />
|
|
1181
|
+
</param>
|
|
1182
|
+
</endpoint>
|
|
1183
|
+
</api>
|
|
1184
|
+
</server>
|
|
1185
|
+
)
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1188
|
+
#### description
|
|
1189
|
+
|
|
1190
|
+
A description of the `string`.
|
|
1191
|
+
|
|
1192
|
+
*src/app.tsx*
|
|
1193
|
+
```typescript jsx
|
|
1194
|
+
export default (
|
|
1195
|
+
<server>
|
|
1196
|
+
<api>
|
|
1197
|
+
<endpoint method='get' path='/products'>
|
|
1198
|
+
<param
|
|
1199
|
+
in='query'
|
|
1200
|
+
name='search'>
|
|
1201
|
+
<string
|
|
1202
|
+
description='A search string'
|
|
1203
|
+
/>
|
|
1204
|
+
</param>
|
|
1205
|
+
</endpoint>
|
|
1206
|
+
</api>
|
|
1207
|
+
</server>
|
|
1208
|
+
)
|
|
1209
|
+
```
|
|
1210
|
+
|
|
1211
|
+
#### values
|
|
1212
|
+
|
|
1213
|
+
The enumeration of available `values`.
|
|
1214
|
+
If you provide the parameter value, which is not in the `values`, the server returns an error.
|
|
1215
|
+
|
|
1216
|
+
*src/app.tsx*
|
|
1217
|
+
```typescript jsx
|
|
1218
|
+
export default (
|
|
1219
|
+
<server>
|
|
1220
|
+
<api>
|
|
1221
|
+
<endpoint method='get' path='/users'>
|
|
1222
|
+
<param
|
|
1223
|
+
in='query'
|
|
1224
|
+
name='status'>
|
|
1225
|
+
<string
|
|
1226
|
+
default='active'
|
|
1227
|
+
values={[
|
|
1228
|
+
'active',
|
|
1229
|
+
'inactive',
|
|
1230
|
+
]}
|
|
1231
|
+
/>
|
|
1232
|
+
</param>
|
|
1233
|
+
</endpoint>
|
|
1234
|
+
</api>
|
|
1235
|
+
</server>
|
|
1236
|
+
)
|
|
1237
|
+
```
|
|
1238
|
+
|
|
1239
|
+
#### min, max
|
|
1240
|
+
|
|
1241
|
+
Those two props validate the `string` value by minimum and maximum length.
|
|
1242
|
+
|
|
1243
|
+
*src/app.tsx*
|
|
1244
|
+
```typescript jsx
|
|
1245
|
+
export default (
|
|
1246
|
+
<server>
|
|
1247
|
+
<api>
|
|
1248
|
+
<endpoint method='get' path='/products'>
|
|
1249
|
+
<param in='query' name='name'>
|
|
1250
|
+
<string min={1} max={128} />
|
|
1251
|
+
</param>
|
|
1252
|
+
</endpoint>
|
|
1253
|
+
</api>
|
|
1254
|
+
</server>
|
|
1255
|
+
)
|
|
1256
|
+
```
|
|
1257
|
+
|
|
1258
|
+
#### pattern
|
|
1259
|
+
|
|
1260
|
+
A `string` of `RegExp` or `RegExp`.
|
|
1261
|
+
|
|
1262
|
+
*src/app.tsx*
|
|
1263
|
+
```typescript jsx
|
|
1264
|
+
export default (
|
|
1265
|
+
<server>
|
|
1266
|
+
<api>
|
|
1267
|
+
<endpoint method='get' path='/products'>
|
|
1268
|
+
<param in='query' name='friendlyName'>
|
|
1269
|
+
<string pattern='^[a-z_0-9]+$' />
|
|
1270
|
+
</param>
|
|
1271
|
+
</endpoint>
|
|
1272
|
+
</api>
|
|
1273
|
+
</server>
|
|
1274
|
+
)
|
|
1275
|
+
```
|
|
1276
|
+
|
|
1277
|
+
If you make a request to the API endpoint,
|
|
1278
|
+
with query parameter of `friendlyName` equals `no-friendly` (as example),
|
|
1279
|
+
you get an error:
|
|
1280
|
+
|
|
1281
|
+
```json
|
|
1282
|
+
{
|
|
1283
|
+
"error": "requestValidation",
|
|
1284
|
+
"data": {
|
|
1285
|
+
"error": "reg",
|
|
1286
|
+
"data": {
|
|
1287
|
+
"key": "friendlyName"
|
|
1288
|
+
},
|
|
1289
|
+
"in": "search"
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
```
|
|
1293
|
+
|
|
1294
|
+
#### patternId
|
|
1295
|
+
|
|
1296
|
+
This property adds an id of the pattern expression in error response.
|
|
1297
|
+
For example, You can use the id to load error message translations.
|
|
1298
|
+
|
|
1299
|
+
*src/app.tsx*
|
|
1300
|
+
```typescript jsx
|
|
1301
|
+
export default (
|
|
1302
|
+
<server>
|
|
1303
|
+
<api>
|
|
1304
|
+
<endpoint method='get' path='/products'>
|
|
1305
|
+
<param in='query' name='friendlyName'>
|
|
1306
|
+
<string
|
|
1307
|
+
pattern='^[a-z_0-9]+$'
|
|
1308
|
+
patternID='fname'
|
|
1309
|
+
/>
|
|
1310
|
+
</param>
|
|
1311
|
+
</endpoint>
|
|
1312
|
+
</api>
|
|
1313
|
+
</server>
|
|
1314
|
+
)
|
|
1315
|
+
```
|
|
1316
|
+
|
|
1317
|
+
If you make a request to the API endpoint,
|
|
1318
|
+
with query parameter of `friendlyName` equals `no-friendly` (as example),
|
|
1319
|
+
you get an error:
|
|
1320
|
+
|
|
1321
|
+
```json
|
|
1322
|
+
{
|
|
1323
|
+
"error": "requestValidation",
|
|
1324
|
+
"data": {
|
|
1325
|
+
"error": "reg",
|
|
1326
|
+
"data": {
|
|
1327
|
+
"key": "friendlyName",
|
|
1328
|
+
"regId": "fname"
|
|
1329
|
+
},
|
|
1330
|
+
"in": "search"
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
```
|
|
1334
|
+
|
|
1335
|
+
### \<number>
|
|
1336
|
+
|
|
1337
|
+
[← back](#primitive-data)
|
|
1338
|
+
|
|
1339
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
1340
|
+
It defines `number` value for a parent element.
|
|
1341
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
1342
|
+
|
|
1343
|
+
Correct numbers are from `-9007199254740991` to `9007199254740991`.
|
|
1344
|
+
This is a value of `Number.MAX_SAFE_INTEGER`.
|
|
1345
|
+
|
|
1346
|
+
*src/app.tsx*
|
|
1347
|
+
```typescript jsx
|
|
1348
|
+
export default (
|
|
1349
|
+
<server>
|
|
1350
|
+
<api>
|
|
1351
|
+
<endpoint method='get' path='/users'>
|
|
1352
|
+
<param
|
|
1353
|
+
in='query'
|
|
1354
|
+
name='minAge'>
|
|
1355
|
+
<number />
|
|
1356
|
+
</param>
|
|
1357
|
+
</endpoint>
|
|
1358
|
+
</api>
|
|
1359
|
+
</server>
|
|
1360
|
+
)
|
|
1361
|
+
```
|
|
1362
|
+
|
|
1363
|
+
*This example defines a `GET` endpoint on `/users` which has an optional query `number` parameter of `minAge`.*
|
|
1364
|
+
|
|
1365
|
+
#### default
|
|
1366
|
+
|
|
1367
|
+
A default value for the `number`.
|
|
1368
|
+
|
|
1369
|
+
*src/app.tsx*
|
|
1370
|
+
```typescript jsx
|
|
1371
|
+
export default (
|
|
1372
|
+
<server>
|
|
1373
|
+
<api>
|
|
1374
|
+
<endpoint method='get' path='/users'>
|
|
1375
|
+
<param
|
|
1376
|
+
in='query'
|
|
1377
|
+
name='minAge'>
|
|
1378
|
+
<number default={18} />
|
|
1379
|
+
</param>
|
|
1380
|
+
</endpoint>
|
|
1381
|
+
</api>
|
|
1382
|
+
</server>
|
|
1383
|
+
)
|
|
1384
|
+
```
|
|
1385
|
+
|
|
1386
|
+
*By default, `minAge` query param equals `18`*
|
|
1387
|
+
|
|
1388
|
+
#### example
|
|
1389
|
+
|
|
1390
|
+
An example value.
|
|
1391
|
+
|
|
1392
|
+
*src/app.tsx*
|
|
1393
|
+
```typescript jsx
|
|
1394
|
+
export default (
|
|
1395
|
+
<server>
|
|
1396
|
+
<api>
|
|
1397
|
+
<endpoint method='get' path='/users'>
|
|
1398
|
+
<param
|
|
1399
|
+
in='query'
|
|
1400
|
+
name='minAge'>
|
|
1401
|
+
<number example={18} />
|
|
1402
|
+
</param>
|
|
1403
|
+
</endpoint>
|
|
1404
|
+
</api>
|
|
1405
|
+
</server>
|
|
1406
|
+
)
|
|
1407
|
+
```
|
|
1408
|
+
|
|
1409
|
+
#### description
|
|
1410
|
+
|
|
1411
|
+
A description of the `number`.
|
|
1412
|
+
|
|
1413
|
+
*src/app.tsx*
|
|
1414
|
+
```typescript jsx
|
|
1415
|
+
export default (
|
|
1416
|
+
<server>
|
|
1417
|
+
<api>
|
|
1418
|
+
<endpoint method='get' path='/users'>
|
|
1419
|
+
<param
|
|
1420
|
+
in='query'
|
|
1421
|
+
name='minAge'>
|
|
1422
|
+
<number
|
|
1423
|
+
example={18}
|
|
1424
|
+
description='Age value'
|
|
1425
|
+
/>
|
|
1426
|
+
</param>
|
|
1427
|
+
</endpoint>
|
|
1428
|
+
</api>
|
|
1429
|
+
</server>
|
|
1430
|
+
)
|
|
1431
|
+
```
|
|
1432
|
+
|
|
1433
|
+
#### values
|
|
1434
|
+
|
|
1435
|
+
The enumeration of available `values`.
|
|
1436
|
+
If you provide the parameter value, which is not in the `values`, the server returns an error.
|
|
1437
|
+
|
|
1438
|
+
*src/app.tsx*
|
|
1439
|
+
```typescript jsx
|
|
1440
|
+
export default (
|
|
1441
|
+
<server>
|
|
1442
|
+
<api>
|
|
1443
|
+
<endpoint method='get' path='/users'>
|
|
1444
|
+
<param
|
|
1445
|
+
in='query'
|
|
1446
|
+
name='minAge'>
|
|
1447
|
+
<number
|
|
1448
|
+
example={18}
|
|
1449
|
+
values={[
|
|
1450
|
+
12,
|
|
1451
|
+
16,
|
|
1452
|
+
18,
|
|
1453
|
+
21,
|
|
1454
|
+
]}
|
|
1455
|
+
/>
|
|
1456
|
+
</param>
|
|
1457
|
+
</endpoint>
|
|
1458
|
+
</api>
|
|
1459
|
+
</server>
|
|
1460
|
+
)
|
|
1461
|
+
```
|
|
1462
|
+
|
|
1463
|
+
#### min, max
|
|
1464
|
+
|
|
1465
|
+
Those two props validate the number value by minimum and maximum values.
|
|
1466
|
+
|
|
1467
|
+
*src/app.tsx*
|
|
1468
|
+
```typescript jsx
|
|
1469
|
+
export default (
|
|
1470
|
+
<server>
|
|
1471
|
+
<api>
|
|
1472
|
+
<endpoint method='get' path='/products'>
|
|
1473
|
+
<param in='query' name='rating'>
|
|
1474
|
+
<number min={1} max={5} />
|
|
1475
|
+
</param>
|
|
1476
|
+
</endpoint>
|
|
1477
|
+
</api>
|
|
1478
|
+
</server>
|
|
1479
|
+
)
|
|
1480
|
+
```
|
|
1481
|
+
|
|
1482
|
+
*In this example `/products?rating=5` is valid and `/products?rating=6` is not*
|
|
1483
|
+
|
|
1484
|
+
### \<integer>
|
|
1485
|
+
|
|
1486
|
+
[← back](#primitive-data)
|
|
1487
|
+
|
|
1488
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
1489
|
+
It defines `integer` value for a parent element.
|
|
1490
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
1491
|
+
|
|
1492
|
+
*src/app.tsx*
|
|
1493
|
+
```typescript jsx
|
|
1494
|
+
export default (
|
|
1495
|
+
<server>
|
|
1496
|
+
<api>
|
|
1497
|
+
<endpoint method='get' path='/users'>
|
|
1498
|
+
<param
|
|
1499
|
+
in='query'
|
|
1500
|
+
name='minAge'>
|
|
1501
|
+
<integer />
|
|
1502
|
+
</param>
|
|
1503
|
+
</endpoint>
|
|
1504
|
+
</api>
|
|
1505
|
+
</server>
|
|
1506
|
+
)
|
|
1507
|
+
```
|
|
1508
|
+
|
|
1509
|
+
*This example defines a `GET` endpoint on `/users` which has an optional query `integer` parameter of `minAge`.*
|
|
1510
|
+
|
|
1511
|
+
#### format
|
|
1512
|
+
|
|
1513
|
+
You can set up the `integer` format.
|
|
1514
|
+
Possible values are `int32` or `int64`.
|
|
1515
|
+
By default, there are `int32` used.
|
|
1516
|
+
|
|
1517
|
+
The format of `int32` means a number from `-2147483647` to `2147483647`.
|
|
1518
|
+
The format of `int64` converts the value to `BigInt` and placed between `-9223372036854775807` and `9223372036854775807`
|
|
1519
|
+
|
|
1520
|
+
|
|
1521
|
+
*src/app.tsx*
|
|
1522
|
+
```typescript jsx
|
|
1523
|
+
export default (
|
|
1524
|
+
<server>
|
|
1525
|
+
<api>
|
|
1526
|
+
<endpoint method='get' path='/users'>
|
|
1527
|
+
<param
|
|
1528
|
+
in='query'
|
|
1529
|
+
name='minAge'>
|
|
1530
|
+
<integer format='int64' />
|
|
1531
|
+
</param>
|
|
1532
|
+
</endpoint>
|
|
1533
|
+
</api>
|
|
1534
|
+
</server>
|
|
1535
|
+
)
|
|
1536
|
+
```
|
|
1537
|
+
|
|
1538
|
+
#### default
|
|
1539
|
+
|
|
1540
|
+
A default value for the `integer`.
|
|
1541
|
+
|
|
1542
|
+
*src/app.tsx*
|
|
1543
|
+
```typescript jsx
|
|
1544
|
+
export default (
|
|
1545
|
+
<server>
|
|
1546
|
+
<api>
|
|
1547
|
+
<endpoint method='get' path='/users'>
|
|
1548
|
+
<param
|
|
1549
|
+
in='query'
|
|
1550
|
+
name='minAge'>
|
|
1551
|
+
<integer default={18} />
|
|
1552
|
+
</param>
|
|
1553
|
+
</endpoint>
|
|
1554
|
+
</api>
|
|
1555
|
+
</server>
|
|
1556
|
+
)
|
|
1557
|
+
```
|
|
1558
|
+
|
|
1559
|
+
*By default, `minAge` query param equals `18`*
|
|
1560
|
+
|
|
1561
|
+
#### example
|
|
1562
|
+
|
|
1563
|
+
An example value.
|
|
1564
|
+
|
|
1565
|
+
*src/app.tsx*
|
|
1566
|
+
```typescript jsx
|
|
1567
|
+
export default (
|
|
1568
|
+
<server>
|
|
1569
|
+
<api>
|
|
1570
|
+
<endpoint method='get' path='/users'>
|
|
1571
|
+
<param
|
|
1572
|
+
in='query'
|
|
1573
|
+
name='minAge'>
|
|
1574
|
+
<integer example={18} />
|
|
1575
|
+
</param>
|
|
1576
|
+
</endpoint>
|
|
1577
|
+
</api>
|
|
1578
|
+
</server>
|
|
1579
|
+
)
|
|
1580
|
+
```
|
|
1581
|
+
|
|
1582
|
+
#### description
|
|
1583
|
+
|
|
1584
|
+
A description of the `integer`.
|
|
1585
|
+
|
|
1586
|
+
*src/app.tsx*
|
|
1587
|
+
```typescript jsx
|
|
1588
|
+
export default (
|
|
1589
|
+
<server>
|
|
1590
|
+
<api>
|
|
1591
|
+
<endpoint method='get' path='/users'>
|
|
1592
|
+
<param
|
|
1593
|
+
in='query'
|
|
1594
|
+
name='minAge'>
|
|
1595
|
+
<integer
|
|
1596
|
+
example={18}
|
|
1597
|
+
description='Age value'
|
|
1598
|
+
/>
|
|
1599
|
+
</param>
|
|
1600
|
+
</endpoint>
|
|
1601
|
+
</api>
|
|
1602
|
+
</server>
|
|
1603
|
+
)
|
|
1604
|
+
```
|
|
1605
|
+
|
|
1606
|
+
#### values
|
|
1607
|
+
|
|
1608
|
+
The enumeration of available `values`.
|
|
1609
|
+
If you provide the parameter value, which is not in the `values`, the server returns an error.
|
|
1610
|
+
|
|
1611
|
+
*src/app.tsx*
|
|
1612
|
+
```typescript jsx
|
|
1613
|
+
export default (
|
|
1614
|
+
<server>
|
|
1615
|
+
<api>
|
|
1616
|
+
<endpoint method='get' path='/users'>
|
|
1617
|
+
<param
|
|
1618
|
+
in='query'
|
|
1619
|
+
name='minAge'>
|
|
1620
|
+
<integer
|
|
1621
|
+
example={18}
|
|
1622
|
+
values={[
|
|
1623
|
+
12,
|
|
1624
|
+
16,
|
|
1625
|
+
18,
|
|
1626
|
+
21,
|
|
1627
|
+
]}
|
|
1628
|
+
/>
|
|
1629
|
+
</param>
|
|
1630
|
+
</endpoint>
|
|
1631
|
+
</api>
|
|
1632
|
+
</server>
|
|
1633
|
+
)
|
|
1634
|
+
```
|
|
1635
|
+
|
|
1636
|
+
#### min, max
|
|
1637
|
+
|
|
1638
|
+
Those two props validate the number value by minimum and maximum values.
|
|
1639
|
+
|
|
1640
|
+
*src/app.tsx*
|
|
1641
|
+
```typescript jsx
|
|
1642
|
+
export default (
|
|
1643
|
+
<server>
|
|
1644
|
+
<api>
|
|
1645
|
+
<endpoint method='get' path='/products'>
|
|
1646
|
+
<param in='query' name='rating'>
|
|
1647
|
+
<integer min={1} max={5} />
|
|
1648
|
+
</param>
|
|
1649
|
+
</endpoint>
|
|
1650
|
+
</api>
|
|
1651
|
+
</server>
|
|
1652
|
+
)
|
|
1653
|
+
```
|
|
1654
|
+
|
|
1655
|
+
*In this example `/products?rating=5` is valid and `/products?rating=6` is not*
|
|
1656
|
+
|
|
1657
|
+
### \<date>
|
|
1658
|
+
|
|
1659
|
+
[← back](#primitive-data)
|
|
1660
|
+
|
|
1661
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
1662
|
+
It defines `date` value for a parent element.
|
|
1663
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
1664
|
+
|
|
1665
|
+
*src/app.tsx*
|
|
1666
|
+
```typescript jsx
|
|
1667
|
+
export default (
|
|
1668
|
+
<server>
|
|
1669
|
+
<api>
|
|
1670
|
+
<endpoint method='get' path='/users'>
|
|
1671
|
+
<param
|
|
1672
|
+
in='query'
|
|
1673
|
+
name='birthday'>
|
|
1674
|
+
<date />
|
|
1675
|
+
</param>
|
|
1676
|
+
</endpoint>
|
|
1677
|
+
</api>
|
|
1678
|
+
</server>
|
|
1679
|
+
)
|
|
1680
|
+
```
|
|
1681
|
+
|
|
1682
|
+
#### default
|
|
1683
|
+
|
|
1684
|
+
A default value for the `date`.
|
|
1685
|
+
Available values:
|
|
1686
|
+
- `string` - the date in ISO format
|
|
1687
|
+
- `number` - date timestamp
|
|
1688
|
+
- `Date` - JavaScript `Date` format
|
|
1689
|
+
- `'now'` - the string defines current date as default value.
|
|
1690
|
+
|
|
1691
|
+
*src/app.tsx*
|
|
1692
|
+
```typescript jsx
|
|
1693
|
+
export default (
|
|
1694
|
+
<server>
|
|
1695
|
+
<api>
|
|
1696
|
+
<endpoint method='get' path='/users'>
|
|
1697
|
+
<param
|
|
1698
|
+
in='query'
|
|
1699
|
+
name='birthday'>
|
|
1700
|
+
<date default='1950-02-15' />
|
|
1701
|
+
</param>
|
|
1702
|
+
</endpoint>
|
|
1703
|
+
</api>
|
|
1704
|
+
</server>
|
|
1705
|
+
)
|
|
1706
|
+
```
|
|
1707
|
+
|
|
1708
|
+
#### values
|
|
1709
|
+
|
|
1710
|
+
The enumeration of available `values`.
|
|
1711
|
+
If you provide the parameter value, which is not in the `values`, the server returns an error.
|
|
1712
|
+
|
|
1713
|
+
Available values:
|
|
1714
|
+
- `string` - the date in ISO format
|
|
1715
|
+
- `number` - date timestamp
|
|
1716
|
+
- `Date` - JavaScript `Date` format
|
|
1717
|
+
|
|
1718
|
+
*src/app.tsx*
|
|
1719
|
+
```typescript jsx
|
|
1720
|
+
export default (
|
|
1721
|
+
<server>
|
|
1722
|
+
<api>
|
|
1723
|
+
<endpoint method='get' path='/users'>
|
|
1724
|
+
<param
|
|
1725
|
+
in='query'
|
|
1726
|
+
name='birthday'>
|
|
1727
|
+
<date
|
|
1728
|
+
values={[
|
|
1729
|
+
1,
|
|
1730
|
+
new Date(),
|
|
1731
|
+
'1950-02-15',
|
|
1732
|
+
]}
|
|
1733
|
+
/>
|
|
1734
|
+
</param>
|
|
1735
|
+
</endpoint>
|
|
1736
|
+
</api>
|
|
1737
|
+
</server>
|
|
1738
|
+
)
|
|
1739
|
+
```
|
|
1740
|
+
|
|
1741
|
+
#### example
|
|
1742
|
+
|
|
1743
|
+
An example value.
|
|
1744
|
+
|
|
1745
|
+
Available values:
|
|
1746
|
+
- `string` - the date in ISO format
|
|
1747
|
+
- `number` - date timestamp
|
|
1748
|
+
- `Date` - JavaScript `Date` format
|
|
1749
|
+
- `'now'` - the string defines server start date as example.
|
|
1750
|
+
|
|
1751
|
+
*src/app.tsx*
|
|
1752
|
+
```typescript jsx
|
|
1753
|
+
export default (
|
|
1754
|
+
<server>
|
|
1755
|
+
<api>
|
|
1756
|
+
<endpoint method='get' path='/users'>
|
|
1757
|
+
<param
|
|
1758
|
+
in='query'
|
|
1759
|
+
name='birthday'>
|
|
1760
|
+
<date example={0} />
|
|
1761
|
+
</param>
|
|
1762
|
+
</endpoint>
|
|
1763
|
+
</api>
|
|
1764
|
+
</server>
|
|
1765
|
+
)
|
|
1766
|
+
```
|
|
1767
|
+
|
|
1768
|
+
#### description
|
|
1769
|
+
|
|
1770
|
+
A description of the `date`.
|
|
1771
|
+
|
|
1772
|
+
*src/app.tsx*
|
|
1773
|
+
```typescript jsx
|
|
1774
|
+
export default (
|
|
1775
|
+
<server>
|
|
1776
|
+
<api>
|
|
1777
|
+
<endpoint method='get' path='/users'>
|
|
1778
|
+
<param
|
|
1779
|
+
in='query'
|
|
1780
|
+
name='birthday'>
|
|
1781
|
+
<date
|
|
1782
|
+
description='The user birthday'
|
|
1783
|
+
/>
|
|
1784
|
+
</param>
|
|
1785
|
+
</endpoint>
|
|
1786
|
+
</api>
|
|
1787
|
+
</server>
|
|
1788
|
+
)
|
|
1789
|
+
```
|
|
1790
|
+
|
|
1791
|
+
#### min, max
|
|
1792
|
+
|
|
1793
|
+
Those two pros limit the date period.
|
|
1794
|
+
|
|
1795
|
+
Available values:
|
|
1796
|
+
- `string` - the date in ISO format
|
|
1797
|
+
- `number` - date timestamp
|
|
1798
|
+
- `Date` - JavaScript `Date` format
|
|
1799
|
+
- `'now'` - the string defines current server date as default.
|
|
1800
|
+
|
|
1801
|
+
*src/app.tsx*
|
|
1802
|
+
```typescript jsx
|
|
1803
|
+
export default (
|
|
1804
|
+
<server>
|
|
1805
|
+
<api>
|
|
1806
|
+
<endpoint method='get' path='/users'>
|
|
1807
|
+
<param
|
|
1808
|
+
in='query'
|
|
1809
|
+
name='birthday'>
|
|
1810
|
+
<date
|
|
1811
|
+
min='01-01-1900'
|
|
1812
|
+
max='now'
|
|
1813
|
+
description='The user birthday'
|
|
1814
|
+
/>
|
|
1815
|
+
</param>
|
|
1816
|
+
</endpoint>
|
|
1817
|
+
</api>
|
|
1818
|
+
</server>
|
|
1819
|
+
)
|
|
1820
|
+
```
|
|
1821
|
+
|
|
1822
|
+
### \<uuid>
|
|
1823
|
+
|
|
1824
|
+
[← back](#primitive-data)
|
|
1825
|
+
|
|
1826
|
+
Universally unique identifier.
|
|
1827
|
+
|
|
1828
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
1829
|
+
It defines `string` value in `uuid` format for a parent element.
|
|
1830
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
1831
|
+
|
|
1832
|
+
*src/app.tsx*
|
|
1833
|
+
```typescript jsx
|
|
1834
|
+
export default (
|
|
1835
|
+
<server>
|
|
1836
|
+
<api>
|
|
1837
|
+
<endpoint method='post' path='/users'>
|
|
1838
|
+
<param
|
|
1839
|
+
in='cookie'
|
|
1840
|
+
name='userId'>
|
|
1841
|
+
<uuid />
|
|
1842
|
+
</param>
|
|
1843
|
+
</endpoint>
|
|
1844
|
+
</api>
|
|
1845
|
+
</server>
|
|
1846
|
+
)
|
|
1847
|
+
```
|
|
1848
|
+
|
|
1849
|
+
#### default
|
|
1850
|
+
|
|
1851
|
+
A default value for the `uuid`.
|
|
1852
|
+
|
|
1853
|
+
Available values:
|
|
1854
|
+
- `string` in uuid format
|
|
1855
|
+
- `new` generates a new uuid
|
|
1856
|
+
|
|
1857
|
+
*src/app.tsx*
|
|
1858
|
+
```typescript jsx
|
|
1859
|
+
export default (
|
|
1860
|
+
<server>
|
|
1861
|
+
<api>
|
|
1862
|
+
<endpoint method='post' path='/users'>
|
|
1863
|
+
<param
|
|
1864
|
+
in='cookie'
|
|
1865
|
+
name='userId'>
|
|
1866
|
+
<uuid default='new' />
|
|
1867
|
+
</param>
|
|
1868
|
+
</endpoint>
|
|
1869
|
+
</api>
|
|
1870
|
+
</server>
|
|
1871
|
+
)
|
|
1872
|
+
```
|
|
1873
|
+
|
|
1874
|
+
#### values
|
|
1875
|
+
|
|
1876
|
+
The enumeration of available `values`.
|
|
1877
|
+
If you provide the parameter value, which is not in the `values`, the server returns an error.
|
|
1878
|
+
|
|
1879
|
+
*src/app.tsx*
|
|
1880
|
+
```typescript jsx
|
|
1881
|
+
export default (
|
|
1882
|
+
<server>
|
|
1883
|
+
<api>
|
|
1884
|
+
<endpoint method='post' path='/users'>
|
|
1885
|
+
<param
|
|
1886
|
+
in='header'
|
|
1887
|
+
name='uuid'>
|
|
1888
|
+
<uuid
|
|
1889
|
+
values={[
|
|
1890
|
+
'123e4567-e89b-12d3-a456-426655440000',
|
|
1891
|
+
'123e4567-e89b-12d3-a456-426614174000',
|
|
1892
|
+
]}
|
|
1893
|
+
/>
|
|
1894
|
+
</param>
|
|
1895
|
+
</endpoint>
|
|
1896
|
+
</api>
|
|
1897
|
+
</server>
|
|
1898
|
+
)
|
|
1899
|
+
```
|
|
1900
|
+
|
|
1901
|
+
#### example
|
|
1902
|
+
|
|
1903
|
+
An example value.
|
|
1904
|
+
|
|
1905
|
+
*src/app.tsx*
|
|
1906
|
+
```typescript jsx
|
|
1907
|
+
export default (
|
|
1908
|
+
<server>
|
|
1909
|
+
<api>
|
|
1910
|
+
<endpoint method='post' path='/users'>
|
|
1911
|
+
<param
|
|
1912
|
+
in='query'
|
|
1913
|
+
name='active'>
|
|
1914
|
+
<uuid
|
|
1915
|
+
default='new'
|
|
1916
|
+
example='123e4567-e89b-12d3-a456-426655440000'
|
|
1917
|
+
/>
|
|
1918
|
+
</param>
|
|
1919
|
+
</endpoint>
|
|
1920
|
+
</api>
|
|
1921
|
+
</server>
|
|
1922
|
+
)
|
|
1923
|
+
```
|
|
1924
|
+
|
|
1925
|
+
#### description
|
|
1926
|
+
|
|
1927
|
+
A description of the `boolean`.
|
|
1928
|
+
|
|
1929
|
+
*src/app.tsx*
|
|
1930
|
+
```typescript jsx
|
|
1931
|
+
export default (
|
|
1932
|
+
<server>
|
|
1933
|
+
<api>
|
|
1934
|
+
<endpoint method='post' path='/users'>
|
|
1935
|
+
<param
|
|
1936
|
+
in='cookie'
|
|
1937
|
+
name='userId'>
|
|
1938
|
+
<uuid
|
|
1939
|
+
default='new'
|
|
1940
|
+
example='123e4567-e89b-12d3-a456-426655440000'
|
|
1941
|
+
description='User ID for a new user'
|
|
1942
|
+
/>
|
|
1943
|
+
</param>
|
|
1944
|
+
</endpoint>
|
|
1945
|
+
</api>
|
|
1946
|
+
</server>
|
|
1947
|
+
)
|
|
1948
|
+
```
|
|
1949
|
+
|
|
1950
|
+
### \<binary>
|
|
1951
|
+
|
|
1952
|
+
[← back](#primitive-data)
|
|
1953
|
+
|
|
1954
|
+
This is a binary type of data.
|
|
1955
|
+
There is one way to get the type, it is `multipart/form-data` usage.
|
|
1956
|
+
|
|
1957
|
+
*src/app.tsx*
|
|
1958
|
+
```typescript jsx
|
|
1959
|
+
export default (
|
|
1960
|
+
<server>
|
|
1961
|
+
<api>
|
|
1962
|
+
<endpoint method='post' path='/partner'>
|
|
1963
|
+
<body>
|
|
1964
|
+
<object>
|
|
1965
|
+
<field key='icon'>
|
|
1966
|
+
<binary />
|
|
1967
|
+
</field>
|
|
1968
|
+
<field key='name'>
|
|
1969
|
+
<string />
|
|
1970
|
+
</field>
|
|
1971
|
+
</object>
|
|
1972
|
+
</body>
|
|
1973
|
+
</endpoint>
|
|
1974
|
+
</api>
|
|
1975
|
+
</server>
|
|
1976
|
+
)
|
|
1977
|
+
```
|
|
1978
|
+
|
|
1979
|
+
#### description
|
|
1980
|
+
|
|
1981
|
+
A description of the `binary`.
|
|
1982
|
+
|
|
1983
|
+
*src/app.tsx*
|
|
1984
|
+
```typescript jsx
|
|
1985
|
+
export default (
|
|
1986
|
+
<server>
|
|
1987
|
+
<api>
|
|
1988
|
+
<endpoint method='post' path='/partner'>
|
|
1989
|
+
<body>
|
|
1990
|
+
<object>
|
|
1991
|
+
<field key='icon'>
|
|
1992
|
+
<binary
|
|
1993
|
+
description='Square icon of the partner'
|
|
1994
|
+
/>
|
|
1995
|
+
</field>
|
|
1996
|
+
</object>
|
|
1997
|
+
</body>
|
|
1998
|
+
</endpoint>
|
|
1999
|
+
</api>
|
|
2000
|
+
</server>
|
|
2001
|
+
)
|
|
2002
|
+
```
|
|
2003
|
+
|
|
2004
|
+
#### accept
|
|
2005
|
+
|
|
2006
|
+
This prop defines available file format.
|
|
2007
|
+
It works the same as [accept](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept) attribute of HTML input element.
|
|
2008
|
+
|
|
2009
|
+
*src/app.tsx*
|
|
2010
|
+
```typescript jsx
|
|
2011
|
+
export default (
|
|
2012
|
+
<server>
|
|
2013
|
+
<api>
|
|
2014
|
+
<endpoint method='post' path='/partner'>
|
|
2015
|
+
<body>
|
|
2016
|
+
<object>
|
|
2017
|
+
<field key='icon'>
|
|
2018
|
+
<binary
|
|
2019
|
+
accept='image/jpeg'
|
|
2020
|
+
description='Square icon of the partner'
|
|
2021
|
+
/>
|
|
2022
|
+
</field>
|
|
2023
|
+
</object>
|
|
2024
|
+
</body>
|
|
2025
|
+
</endpoint>
|
|
2026
|
+
</api>
|
|
2027
|
+
</server>
|
|
2028
|
+
)
|
|
2029
|
+
```
|
|
2030
|
+
|
|
2031
|
+
#### min, max
|
|
2032
|
+
|
|
2033
|
+
Those two pros limit the file size.
|
|
2034
|
+
|
|
2035
|
+
*src/app.tsx*
|
|
2036
|
+
```typescript jsx
|
|
2037
|
+
export default (
|
|
2038
|
+
<server>
|
|
2039
|
+
<api>
|
|
2040
|
+
<endpoint method='post' path='/partner'>
|
|
2041
|
+
<body>
|
|
2042
|
+
<object>
|
|
2043
|
+
<field key='icon'>
|
|
2044
|
+
<binary
|
|
2045
|
+
accept='image/jpeg'
|
|
2046
|
+
description='Square icon of the partner'
|
|
2047
|
+
min={1024}
|
|
2048
|
+
max={10 * 1024 ** 2}
|
|
2049
|
+
/>
|
|
2050
|
+
</field>
|
|
2051
|
+
</object>
|
|
2052
|
+
</body>
|
|
2053
|
+
</endpoint>
|
|
2054
|
+
</api>
|
|
2055
|
+
</server>
|
|
2056
|
+
)
|
|
2057
|
+
```
|
|
2058
|
+
|
|
2059
|
+
## List of Data
|
|
2060
|
+
|
|
2061
|
+
[← back](#index)
|
|
2062
|
+
|
|
2063
|
+
[\<tuple>](#tuple)
|
|
2064
|
+
[\<array>](#array)
|
|
2065
|
+
[\<object>](#object)
|
|
2066
|
+
[\<field>](#field)
|
|
2067
|
+
|
|
2068
|
+
---
|
|
2069
|
+
|
|
2070
|
+
### \<tuple>
|
|
2071
|
+
|
|
2072
|
+
[← back](#list-of-data)
|
|
2073
|
+
|
|
2074
|
+
`<tuple>` element specifies schema parameter as a tuple of children elements.
|
|
2075
|
+
|
|
2076
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
2077
|
+
|
|
2078
|
+
*src/app.tsx*
|
|
2079
|
+
```typescript jsx
|
|
2080
|
+
export default (
|
|
2081
|
+
<server>
|
|
2082
|
+
<api>
|
|
2083
|
+
<endpoint method='get' path='/products'>
|
|
2084
|
+
<param name='rating' in='query'>
|
|
2085
|
+
<tuple>
|
|
2086
|
+
<number min={1} max={5} />
|
|
2087
|
+
<number min={1} max={5} />
|
|
2088
|
+
</tuple>
|
|
2089
|
+
</param>
|
|
2090
|
+
</endpoint>
|
|
2091
|
+
</api>
|
|
2092
|
+
</server>
|
|
2093
|
+
)
|
|
2094
|
+
```
|
|
2095
|
+
|
|
2096
|
+
This example defines that, `/products?rating=3&rating=4` is valid and `rating` MUST be from `3` to `4`.
|
|
2097
|
+
Also supports formats `/products?rating[]=3&rating[]=4` and `/products?rating[0]=3&rating[1]=4`.
|
|
2098
|
+
|
|
2099
|
+
`/products?rating=3` or `/products?rating=1&rating=6` returns an error.
|
|
2100
|
+
|
|
2101
|
+
You can add several elements in [\<response>](#response), [\<param>](#param) or [\<body>](#body) to define that one of the element is valid.
|
|
2102
|
+
|
|
2103
|
+
*src/app.tsx*
|
|
2104
|
+
```typescript jsx
|
|
2105
|
+
export default (
|
|
2106
|
+
<server>
|
|
2107
|
+
<api>
|
|
2108
|
+
<endpoint method='get' path='/products'>
|
|
2109
|
+
<param in='query' name='rating'>
|
|
2110
|
+
<number min={1} max={5} />
|
|
2111
|
+
<tuple>
|
|
2112
|
+
<number min={1} max={5} />
|
|
2113
|
+
<number min={1} max={5} />
|
|
2114
|
+
</tuple>
|
|
2115
|
+
</param>
|
|
2116
|
+
</endpoint>
|
|
2117
|
+
</api>
|
|
2118
|
+
</server>
|
|
2119
|
+
)
|
|
2120
|
+
```
|
|
2121
|
+
|
|
2122
|
+
This example defines that, `/products?rating=3&rating=4` is valid and `rating` MUST be from `3` to `4`.
|
|
2123
|
+
Also supports `/products?rating=3`, returns products have `rating` equals `3`.
|
|
2124
|
+
|
|
2125
|
+
`/products?rating=text` or `/products?rating=1&rating=6` returns an error.
|
|
2126
|
+
|
|
2127
|
+
#### default
|
|
2128
|
+
|
|
2129
|
+
Defines default `<tuple>` value.
|
|
2130
|
+
|
|
2131
|
+
*src/app.tsx*
|
|
2132
|
+
```typescript jsx
|
|
2133
|
+
export default (
|
|
2134
|
+
<server>
|
|
2135
|
+
<api>
|
|
2136
|
+
<endpoint method='get' path='/products'>
|
|
2137
|
+
<param in='query' name='rating'>
|
|
2138
|
+
<number min={1} max={5} />
|
|
2139
|
+
<tuple default={[1, 5]}>
|
|
2140
|
+
<number min={1} max={5} />
|
|
2141
|
+
<number min={1} max={5} />
|
|
2142
|
+
</tuple>
|
|
2143
|
+
</param>
|
|
2144
|
+
</endpoint>
|
|
2145
|
+
</api>
|
|
2146
|
+
</server>
|
|
2147
|
+
)
|
|
2148
|
+
```
|
|
2149
|
+
|
|
2150
|
+
#### example
|
|
2151
|
+
|
|
2152
|
+
Defines an example of the `<tuple>` value.
|
|
2153
|
+
|
|
2154
|
+
*src/app.tsx*
|
|
2155
|
+
```typescript jsx
|
|
2156
|
+
export default (
|
|
2157
|
+
<server>
|
|
2158
|
+
<api>
|
|
2159
|
+
<endpoint method='get' path='/products'>
|
|
2160
|
+
<param in='query' name='rating'>
|
|
2161
|
+
<number min={1} max={5} />
|
|
2162
|
+
<tuple default={[1, 5]} example={[3, 5]}>
|
|
2163
|
+
<number min={1} max={5} />
|
|
2164
|
+
<number min={1} max={5} />
|
|
2165
|
+
</tuple>
|
|
2166
|
+
</param>
|
|
2167
|
+
</endpoint>
|
|
2168
|
+
</api>
|
|
2169
|
+
</server>
|
|
2170
|
+
)
|
|
30
2171
|
```
|
|
31
|
-
*change my-app to work folder name*
|
|
32
2172
|
|
|
33
|
-
|
|
2173
|
+
#### description
|
|
34
2174
|
|
|
35
|
-
|
|
2175
|
+
Defines the `<tuple>` description.
|
|
36
2176
|
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
|
|
40
|
-
|
|
2177
|
+
*src/app.tsx*
|
|
2178
|
+
```typescript jsx
|
|
2179
|
+
export default (
|
|
2180
|
+
<server>
|
|
2181
|
+
<api>
|
|
2182
|
+
<endpoint method='get' path='/products'>
|
|
2183
|
+
<param in='query' name='rating'>
|
|
2184
|
+
<number min={1} max={5} />
|
|
2185
|
+
<tuple
|
|
2186
|
+
description='A range of rating score'
|
|
2187
|
+
default={[1, 5]}
|
|
2188
|
+
example={[3, 5]}>
|
|
2189
|
+
<number min={1} max={5} />
|
|
2190
|
+
<number min={1} max={5} />
|
|
2191
|
+
</tuple>
|
|
2192
|
+
</param>
|
|
2193
|
+
</endpoint>
|
|
2194
|
+
</api>
|
|
2195
|
+
</server>
|
|
2196
|
+
)
|
|
2197
|
+
```
|
|
41
2198
|
|
|
42
|
-
|
|
2199
|
+
### \<array>
|
|
43
2200
|
|
|
44
|
-
|
|
45
|
-
```
|
|
2201
|
+
[← back](#list-of-data)
|
|
46
2202
|
|
|
47
|
-
|
|
48
|
-
To start http(s) server, use `server` element.
|
|
2203
|
+
`<array>` element specifies schema parameter as an array of children elements.
|
|
49
2204
|
|
|
50
|
-
|
|
2205
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
2206
|
+
|
|
2207
|
+
*src/app.tsx*
|
|
51
2208
|
```typescript jsx
|
|
52
2209
|
export default (
|
|
53
2210
|
<server>
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
2211
|
+
<api>
|
|
2212
|
+
<endpoint method='get' path='/products'>
|
|
2213
|
+
<param in='query' name='rating'>
|
|
2214
|
+
<array>
|
|
2215
|
+
<number min={1} max={5} />
|
|
2216
|
+
</array>
|
|
2217
|
+
</param>
|
|
2218
|
+
</endpoint>
|
|
2219
|
+
</api>
|
|
57
2220
|
</server>
|
|
58
2221
|
)
|
|
59
2222
|
```
|
|
60
2223
|
|
|
61
|
-
|
|
62
|
-
|
|
2224
|
+
This example defines that, `/products?rating=3&rating=4` is valid and `rating` MUST be `3` or `4`.
|
|
2225
|
+
Also supports formats `/products?rating[]=3&rating[]=4` and `/products?rating[0]=3&rating[1]=4`.
|
|
2226
|
+
|
|
2227
|
+
`/products?rating=3` and `/products?rating=1&rating=2&rating=3` also support.
|
|
63
2228
|
|
|
64
|
-
|
|
2229
|
+
#### default
|
|
65
2230
|
|
|
66
|
-
|
|
67
|
-
To change the port of the web server you can use `port` prop.
|
|
2231
|
+
Defines default `<array>` value.
|
|
68
2232
|
|
|
2233
|
+
*src/app.tsx*
|
|
69
2234
|
```typescript jsx
|
|
70
2235
|
export default (
|
|
71
|
-
<server
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
2236
|
+
<server>
|
|
2237
|
+
<api>
|
|
2238
|
+
<endpoint method='get' path='/products'>
|
|
2239
|
+
<param in='query' name='rating'>
|
|
2240
|
+
<array default={[1, 2, 3, 4, 5]}>
|
|
2241
|
+
<number min={1} max={5} />
|
|
2242
|
+
</array>
|
|
2243
|
+
</param>
|
|
2244
|
+
</endpoint>
|
|
2245
|
+
</api>
|
|
75
2246
|
</server>
|
|
76
2247
|
)
|
|
77
2248
|
```
|
|
78
2249
|
|
|
79
|
-
|
|
2250
|
+
#### example
|
|
80
2251
|
|
|
81
|
-
|
|
82
|
-
To have https connection you should provide SSL certificate.
|
|
2252
|
+
Defines an example of the `<array>` value.
|
|
83
2253
|
|
|
2254
|
+
*src/app.tsx*
|
|
84
2255
|
```typescript jsx
|
|
85
|
-
const ssl = {
|
|
86
|
-
key: 'local.key',
|
|
87
|
-
cert: 'local.crt'
|
|
88
|
-
}
|
|
89
|
-
|
|
90
2256
|
export default (
|
|
91
|
-
<server
|
|
92
|
-
<
|
|
93
|
-
|
|
94
|
-
|
|
2257
|
+
<server>
|
|
2258
|
+
<api>
|
|
2259
|
+
<endpoint method='get' path='/products'>
|
|
2260
|
+
<param in='query' name='rating'>
|
|
2261
|
+
<array example={[1, 3, 5]}>
|
|
2262
|
+
<number min={1} max={5} />
|
|
2263
|
+
</array>
|
|
2264
|
+
</param>
|
|
2265
|
+
</endpoint>
|
|
2266
|
+
</api>
|
|
95
2267
|
</server>
|
|
96
2268
|
)
|
|
97
2269
|
```
|
|
98
2270
|
|
|
99
|
-
|
|
2271
|
+
#### description
|
|
100
2272
|
|
|
101
|
-
|
|
102
|
-
|
|
2273
|
+
Defines the `<array>` description.
|
|
2274
|
+
|
|
2275
|
+
*src/app.tsx*
|
|
103
2276
|
```typescript jsx
|
|
104
2277
|
export default (
|
|
105
|
-
<server
|
|
106
|
-
<
|
|
107
|
-
|
|
108
|
-
|
|
2278
|
+
<server>
|
|
2279
|
+
<api>
|
|
2280
|
+
<endpoint method='get' path='/products'>
|
|
2281
|
+
<param in='query' name='rating'>
|
|
2282
|
+
<array
|
|
2283
|
+
description='Values of rating score'
|
|
2284
|
+
example={[3, 5]}>
|
|
2285
|
+
<number min={1} max={5} />
|
|
2286
|
+
</array>
|
|
2287
|
+
</param>
|
|
2288
|
+
</endpoint>
|
|
2289
|
+
</api>
|
|
109
2290
|
</server>
|
|
110
2291
|
)
|
|
111
2292
|
```
|
|
112
2293
|
|
|
113
|
-
###
|
|
114
|
-
|
|
2294
|
+
### \<object>
|
|
2295
|
+
|
|
2296
|
+
[← back](#list-of-data)
|
|
2297
|
+
|
|
2298
|
+
The element MUST be placed inside one of [\<response>](#response), [\<param>](#param), [\<body>](#body).
|
|
2299
|
+
It defines `object` value for a parent element.
|
|
2300
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
115
2301
|
|
|
2302
|
+
*src/app.tsx*
|
|
116
2303
|
```typescript jsx
|
|
117
2304
|
export default (
|
|
118
|
-
<server
|
|
119
|
-
<
|
|
120
|
-
|
|
121
|
-
|
|
2305
|
+
<server>
|
|
2306
|
+
<api>
|
|
2307
|
+
<endpoint method='post' path='/users'>
|
|
2308
|
+
<body>
|
|
2309
|
+
<object />
|
|
2310
|
+
</body>
|
|
2311
|
+
</endpoint>
|
|
2312
|
+
</api>
|
|
122
2313
|
</server>
|
|
123
2314
|
)
|
|
124
2315
|
```
|
|
125
2316
|
|
|
126
|
-
|
|
127
|
-
|
|
2317
|
+
#### default
|
|
2318
|
+
|
|
2319
|
+
A default value for the `object`.
|
|
128
2320
|
|
|
2321
|
+
*src/app.tsx*
|
|
129
2322
|
```typescript jsx
|
|
130
2323
|
export default (
|
|
131
|
-
<server
|
|
132
|
-
<
|
|
133
|
-
|
|
134
|
-
|
|
2324
|
+
<server>
|
|
2325
|
+
<api>
|
|
2326
|
+
<endpoint method='post' path='/users'>
|
|
2327
|
+
<body>
|
|
2328
|
+
<object
|
|
2329
|
+
default={{name: 'John'}}
|
|
2330
|
+
/>
|
|
2331
|
+
</body>
|
|
2332
|
+
</endpoint>
|
|
2333
|
+
</api>
|
|
135
2334
|
</server>
|
|
136
2335
|
)
|
|
137
2336
|
```
|
|
138
2337
|
|
|
139
|
-
|
|
140
|
-
|
|
2338
|
+
#### example
|
|
2339
|
+
|
|
2340
|
+
An example value.
|
|
141
2341
|
|
|
2342
|
+
*src/app.tsx*
|
|
142
2343
|
```typescript jsx
|
|
143
2344
|
export default (
|
|
144
|
-
<server
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
2345
|
+
<server>
|
|
2346
|
+
<api>
|
|
2347
|
+
<endpoint method='post' path='/users'>
|
|
2348
|
+
<body>
|
|
2349
|
+
<object
|
|
2350
|
+
example={{name: 'John'}}
|
|
2351
|
+
/>
|
|
2352
|
+
</body>
|
|
2353
|
+
</endpoint>
|
|
2354
|
+
</api>
|
|
149
2355
|
</server>
|
|
150
2356
|
)
|
|
151
2357
|
```
|
|
152
2358
|
|
|
153
|
-
|
|
154
|
-
You can use `html` element to return html content.
|
|
2359
|
+
#### description
|
|
155
2360
|
|
|
2361
|
+
A description of the `object`.
|
|
2362
|
+
|
|
2363
|
+
*src/app.tsx*
|
|
156
2364
|
```typescript jsx
|
|
157
2365
|
export default (
|
|
158
2366
|
<server>
|
|
159
|
-
<
|
|
160
|
-
<
|
|
161
|
-
<head>
|
|
162
|
-
<title>Innet App</title>
|
|
163
|
-
</head>
|
|
2367
|
+
<api>
|
|
2368
|
+
<endpoint method='post' path='/users'>
|
|
164
2369
|
<body>
|
|
165
|
-
|
|
2370
|
+
<object
|
|
2371
|
+
description='The object of a user'
|
|
2372
|
+
/>
|
|
166
2373
|
</body>
|
|
167
|
-
</
|
|
168
|
-
</
|
|
2374
|
+
</endpoint>
|
|
2375
|
+
</api>
|
|
169
2376
|
</server>
|
|
170
2377
|
)
|
|
171
2378
|
```
|
|
172
2379
|
|
|
173
|
-
|
|
2380
|
+
### \<field>
|
|
2381
|
+
|
|
2382
|
+
[← back](#list-of-data)
|
|
2383
|
+
|
|
2384
|
+
The element MUST be placed inside [\<object>](#object).
|
|
2385
|
+
It defines a `field` of an `object` value for a parent element.
|
|
2386
|
+
`@innet/server` formats and validate the value automatically (real-time).
|
|
2387
|
+
|
|
2388
|
+
`key` is REQUIRED prop of `<field>`, it defines a field name of the `<object>`.
|
|
174
2389
|
|
|
2390
|
+
*src/app.tsx*
|
|
175
2391
|
```typescript jsx
|
|
176
|
-
|
|
177
|
-
<
|
|
178
|
-
<
|
|
179
|
-
<
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
2392
|
+
export default (
|
|
2393
|
+
<server>
|
|
2394
|
+
<api>
|
|
2395
|
+
<endpoint method='post' path='/users'>
|
|
2396
|
+
<body>
|
|
2397
|
+
<object>
|
|
2398
|
+
<field key='name' />
|
|
2399
|
+
<field key='surname' />
|
|
2400
|
+
<field key='birthbay' />
|
|
2401
|
+
</object>
|
|
2402
|
+
</body>
|
|
2403
|
+
</endpoint>
|
|
2404
|
+
</api>
|
|
2405
|
+
</server>
|
|
185
2406
|
)
|
|
2407
|
+
```
|
|
2408
|
+
|
|
2409
|
+
#### optional
|
|
2410
|
+
|
|
2411
|
+
By default, any field is required. You can set it as `optional` by this prop.
|
|
186
2412
|
|
|
2413
|
+
*src/app.tsx*
|
|
2414
|
+
```typescript jsx
|
|
187
2415
|
export default (
|
|
188
2416
|
<server>
|
|
189
|
-
<
|
|
190
|
-
|
|
191
|
-
|
|
2417
|
+
<api>
|
|
2418
|
+
<endpoint method='post' path='/users'>
|
|
2419
|
+
<body>
|
|
2420
|
+
<object>
|
|
2421
|
+
<field key='name' />
|
|
2422
|
+
<field key='surname' />
|
|
2423
|
+
<field optional key='birthbay' />
|
|
2424
|
+
</object>
|
|
2425
|
+
</body>
|
|
2426
|
+
</endpoint>
|
|
2427
|
+
</api>
|
|
192
2428
|
</server>
|
|
193
2429
|
)
|
|
194
2430
|
```
|
|
195
2431
|
|
|
196
|
-
##
|
|
197
|
-
You can add an HTTP header into response with `header` element.
|
|
2432
|
+
## Run-Time
|
|
198
2433
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
)
|
|
2434
|
+
Next elements relate to run-time action.
|
|
2435
|
+
This action calls on user request.
|
|
2436
|
+
|
|
2437
|
+
[← back](#index)
|
|
2438
|
+
|
|
2439
|
+
Parent
|
|
2440
|
+
[\<fallback>](#fallback)
|
|
2441
|
+
[\<request>](#request)
|
|
2442
|
+
|
|
2443
|
+
Children
|
|
2444
|
+
[\<success>](#success)
|
|
2445
|
+
[\<error>](#error)
|
|
2446
|
+
[\<proxy>](#proxy)
|
|
2447
|
+
[\<redirect>](#redirect)
|
|
2448
|
+
[\<cms>](#cms)
|
|
2449
|
+
[\<file>](#file)
|
|
2450
|
+
[\<header>](#header)
|
|
2451
|
+
[\<cookie>](#cookie)
|
|
2452
|
+
|
|
2453
|
+
---
|
|
203
2454
|
|
|
2455
|
+
### \<fallback>
|
|
2456
|
+
|
|
2457
|
+
[← back](#run-time)
|
|
2458
|
+
|
|
2459
|
+
By default, `<api>` server returns 404 with empty body.
|
|
2460
|
+
[\<fallback>](#fallback) element defines default server response.
|
|
2461
|
+
This element MUST be placed in `<api>`.
|
|
2462
|
+
You MUST use one [\<fallback>](#fallback) per `<api>`.
|
|
2463
|
+
Can contain elements available inside [\<request>](#request).
|
|
2464
|
+
|
|
2465
|
+
*src/app.tsx*
|
|
2466
|
+
```typescript jsx
|
|
204
2467
|
export default (
|
|
205
2468
|
<server>
|
|
206
|
-
<
|
|
207
|
-
<
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
2469
|
+
<api>
|
|
2470
|
+
<fallback>
|
|
2471
|
+
<error
|
|
2472
|
+
code='unknownEndpoint'
|
|
2473
|
+
/>
|
|
2474
|
+
</fallback>
|
|
2475
|
+
</api>
|
|
211
2476
|
</server>
|
|
212
2477
|
)
|
|
213
2478
|
```
|
|
214
2479
|
|
|
215
|
-
|
|
2480
|
+
If you open the application on any URL except for `/`, you can see the next response.
|
|
216
2481
|
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
2482
|
+
```json
|
|
2483
|
+
{
|
|
2484
|
+
"error": "unknownEndpoint"
|
|
2485
|
+
}
|
|
2486
|
+
```
|
|
2487
|
+
|
|
2488
|
+
The next elements are placed in [\<request>](#request) or [\<fallback>](#fallback)
|
|
221
2489
|
|
|
2490
|
+
### \<request>
|
|
2491
|
+
|
|
2492
|
+
[← back](#run-time)
|
|
2493
|
+
|
|
2494
|
+
This element MUST be placed in `<endpoint>` element.
|
|
2495
|
+
It defines run-time call handler for the endpoint.
|
|
2496
|
+
|
|
2497
|
+
*src/app.tsx*
|
|
2498
|
+
```typescript jsx
|
|
222
2499
|
export default (
|
|
223
2500
|
<server>
|
|
224
|
-
<
|
|
225
|
-
<
|
|
226
|
-
|
|
227
|
-
|
|
2501
|
+
<api>
|
|
2502
|
+
<endpoint method='get' path='/partners'>
|
|
2503
|
+
<request>
|
|
2504
|
+
<success>
|
|
2505
|
+
{{partners: []}}
|
|
2506
|
+
</success>
|
|
2507
|
+
</request>
|
|
2508
|
+
</endpoint>
|
|
2509
|
+
</api>
|
|
228
2510
|
</server>
|
|
229
2511
|
)
|
|
230
2512
|
```
|
|
231
2513
|
|
|
232
|
-
|
|
233
|
-
|
|
2514
|
+
You can place a component inside it.
|
|
2515
|
+
The component will run when the endpoint will be triggered.
|
|
234
2516
|
|
|
2517
|
+
*src/app.tsx*
|
|
235
2518
|
```typescript jsx
|
|
2519
|
+
import { GetPartners } from './GetPartners'
|
|
2520
|
+
|
|
236
2521
|
export default (
|
|
237
2522
|
<server>
|
|
238
|
-
<
|
|
239
|
-
<
|
|
240
|
-
<
|
|
241
|
-
|
|
242
|
-
|
|
2523
|
+
<api>
|
|
2524
|
+
<endpoint method='get' path='/partners'>
|
|
2525
|
+
<request>
|
|
2526
|
+
<GetPartners />
|
|
2527
|
+
</request>
|
|
2528
|
+
</endpoint>
|
|
2529
|
+
</api>
|
|
243
2530
|
</server>
|
|
244
2531
|
)
|
|
245
2532
|
```
|
|
246
2533
|
|
|
247
|
-
|
|
2534
|
+
*src/GetPartners.tsx*
|
|
2535
|
+
```typescript jsx
|
|
2536
|
+
export const GetPartners = () => (
|
|
2537
|
+
<success>
|
|
2538
|
+
{{partners: []}}
|
|
2539
|
+
</success>
|
|
2540
|
+
)
|
|
2541
|
+
```
|
|
2542
|
+
|
|
2543
|
+
### \<success>
|
|
2544
|
+
|
|
2545
|
+
[← back](#run-time)
|
|
248
2546
|
|
|
249
|
-
|
|
2547
|
+
This is a base element to return a success data.
|
|
250
2548
|
|
|
2549
|
+
*src/app.tsx*
|
|
251
2550
|
```typescript jsx
|
|
252
2551
|
export default (
|
|
253
2552
|
<server>
|
|
254
|
-
<
|
|
255
|
-
<
|
|
256
|
-
<
|
|
257
|
-
</
|
|
258
|
-
</
|
|
2553
|
+
<api>
|
|
2554
|
+
<fallback>
|
|
2555
|
+
<success />
|
|
2556
|
+
</fallback>
|
|
2557
|
+
</api>
|
|
259
2558
|
</server>
|
|
260
2559
|
)
|
|
261
2560
|
```
|
|
262
2561
|
|
|
263
|
-
|
|
2562
|
+
You will get a response with `204` status (`noContent`) and without content.
|
|
2563
|
+
|
|
2564
|
+
You can provide some data to the user by children.
|
|
264
2565
|
|
|
265
|
-
|
|
266
|
-
The router helps to handle requests by route.
|
|
2566
|
+
*src/app.tsx*
|
|
267
2567
|
```typescript jsx
|
|
2568
|
+
const data = {...}
|
|
2569
|
+
|
|
268
2570
|
export default (
|
|
269
2571
|
<server>
|
|
270
|
-
<
|
|
271
|
-
<
|
|
272
|
-
<
|
|
273
|
-
|
|
274
|
-
|
|
2572
|
+
<api>
|
|
2573
|
+
<fallback>
|
|
2574
|
+
<success>
|
|
2575
|
+
{data}
|
|
2576
|
+
</success>
|
|
2577
|
+
</fallback>
|
|
2578
|
+
</api>
|
|
275
2579
|
</server>
|
|
276
2580
|
)
|
|
277
2581
|
```
|
|
278
2582
|
|
|
279
|
-
|
|
280
|
-
|
|
2583
|
+
You will get `200` status (`ok`), with body equals data.
|
|
2584
|
+
|
|
2585
|
+
#### status
|
|
281
2586
|
|
|
282
|
-
|
|
283
|
-
This property says that the content of the route should be run if the request method equals to the prop.
|
|
2587
|
+
You can set response status by `status` prop of `<success>`.
|
|
284
2588
|
|
|
2589
|
+
*src/app.tsx*
|
|
285
2590
|
```typescript jsx
|
|
2591
|
+
const data = {...}
|
|
2592
|
+
|
|
286
2593
|
export default (
|
|
287
2594
|
<server>
|
|
288
|
-
<
|
|
289
|
-
<
|
|
290
|
-
<
|
|
291
|
-
|
|
292
|
-
|
|
2595
|
+
<api>
|
|
2596
|
+
<fallback>
|
|
2597
|
+
<success status='created'>
|
|
2598
|
+
{data}
|
|
2599
|
+
</success>
|
|
2600
|
+
</fallback>
|
|
2601
|
+
</api>
|
|
293
2602
|
</server>
|
|
294
2603
|
)
|
|
295
2604
|
```
|
|
296
2605
|
|
|
297
|
-
|
|
298
|
-
|
|
2606
|
+
You will get `201` status (`created`), with data as a content.
|
|
2607
|
+
|
|
2608
|
+
You can use a number of `status` prop.
|
|
299
2609
|
|
|
2610
|
+
*src/app.tsx*
|
|
300
2611
|
```typescript jsx
|
|
2612
|
+
const data = {...}
|
|
2613
|
+
|
|
301
2614
|
export default (
|
|
302
2615
|
<server>
|
|
303
|
-
<
|
|
304
|
-
<
|
|
305
|
-
<
|
|
306
|
-
|
|
307
|
-
|
|
2616
|
+
<api>
|
|
2617
|
+
<fallback>
|
|
2618
|
+
<success status={201}>
|
|
2619
|
+
{data}
|
|
2620
|
+
</success>
|
|
2621
|
+
</fallback>
|
|
2622
|
+
</api>
|
|
308
2623
|
</server>
|
|
309
2624
|
)
|
|
310
2625
|
```
|
|
311
2626
|
|
|
312
|
-
|
|
2627
|
+
### \<error>
|
|
313
2628
|
|
|
314
|
-
|
|
2629
|
+
[← back](#run-time)
|
|
315
2630
|
|
|
2631
|
+
Returns an error.
|
|
2632
|
+
This element MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
2633
|
+
|
|
2634
|
+
*src/app.tsx*
|
|
316
2635
|
```typescript jsx
|
|
317
2636
|
export default (
|
|
318
2637
|
<server>
|
|
319
|
-
<
|
|
320
|
-
<
|
|
321
|
-
<
|
|
322
|
-
</
|
|
323
|
-
</
|
|
2638
|
+
<api>
|
|
2639
|
+
<fallback>
|
|
2640
|
+
<error />
|
|
2641
|
+
</fallback>
|
|
2642
|
+
</api>
|
|
324
2643
|
</server>
|
|
325
2644
|
)
|
|
326
2645
|
```
|
|
327
2646
|
|
|
328
|
-
|
|
2647
|
+
Place a data into the element to return an error with the data.
|
|
329
2648
|
|
|
2649
|
+
*src/app.tsx*
|
|
330
2650
|
```typescript jsx
|
|
2651
|
+
const data = {...}
|
|
2652
|
+
|
|
331
2653
|
export default (
|
|
332
2654
|
<server>
|
|
333
|
-
<
|
|
334
|
-
<
|
|
335
|
-
<
|
|
336
|
-
|
|
337
|
-
|
|
2655
|
+
<api>
|
|
2656
|
+
<fallback>
|
|
2657
|
+
<error>
|
|
2658
|
+
{data}
|
|
2659
|
+
</error>
|
|
2660
|
+
</fallback>
|
|
2661
|
+
</api>
|
|
338
2662
|
</server>
|
|
339
2663
|
)
|
|
340
2664
|
```
|
|
341
2665
|
|
|
342
|
-
|
|
343
|
-
You can
|
|
2666
|
+
#### status
|
|
2667
|
+
You can change response status by `status` prop. By default, it is `520` (`unknownError`)
|
|
344
2668
|
|
|
2669
|
+
*src/app.tsx*
|
|
345
2670
|
```typescript jsx
|
|
2671
|
+
const data = {
|
|
2672
|
+
message: 'User not found!'
|
|
2673
|
+
}
|
|
2674
|
+
|
|
346
2675
|
export default (
|
|
347
2676
|
<server>
|
|
348
|
-
<
|
|
349
|
-
<
|
|
350
|
-
<
|
|
351
|
-
|
|
352
|
-
|
|
2677
|
+
<api>
|
|
2678
|
+
<fallback>
|
|
2679
|
+
<error status='notFound'>
|
|
2680
|
+
{data}
|
|
2681
|
+
</error>
|
|
2682
|
+
</fallback>
|
|
2683
|
+
</api>
|
|
353
2684
|
</server>
|
|
354
2685
|
)
|
|
355
2686
|
```
|
|
356
2687
|
|
|
357
|
-
|
|
358
|
-
`/test`, `/test/something` matches.
|
|
359
|
-
|
|
360
|
-
### prefix
|
|
361
|
-
|
|
362
|
-
You can use a router inside another one and `prefix` helps reduce path prop.
|
|
2688
|
+
You can use a number with the status prop.
|
|
363
2689
|
|
|
2690
|
+
*src/app.tsx*
|
|
364
2691
|
```typescript jsx
|
|
2692
|
+
const data = {
|
|
2693
|
+
message: 'User not found!'
|
|
2694
|
+
}
|
|
2695
|
+
|
|
365
2696
|
export default (
|
|
366
2697
|
<server>
|
|
367
|
-
<
|
|
368
|
-
<
|
|
369
|
-
<
|
|
370
|
-
|
|
371
|
-
</
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
</router>
|
|
375
|
-
</router>
|
|
376
|
-
</action>
|
|
2698
|
+
<api>
|
|
2699
|
+
<fallback>
|
|
2700
|
+
<error status={404}>
|
|
2701
|
+
{data}
|
|
2702
|
+
</error>
|
|
2703
|
+
</fallback>
|
|
2704
|
+
</api>
|
|
377
2705
|
</server>
|
|
378
2706
|
)
|
|
379
2707
|
```
|
|
380
2708
|
|
|
381
|
-
|
|
2709
|
+
#### code
|
|
2710
|
+
When you use `<error>` element a user get next response body.
|
|
382
2711
|
|
|
383
|
-
|
|
2712
|
+
*for the previous example*
|
|
2713
|
+
```json
|
|
2714
|
+
{
|
|
2715
|
+
"error": "undefined",
|
|
2716
|
+
"data": {
|
|
2717
|
+
"message": "User not found!"
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
```
|
|
384
2721
|
|
|
385
|
-
You can
|
|
2722
|
+
You can change the `error` code by `code` property.
|
|
386
2723
|
|
|
2724
|
+
*src/app.tsx*
|
|
387
2725
|
```typescript jsx
|
|
2726
|
+
const data = {
|
|
2727
|
+
message: 'User not found!'
|
|
2728
|
+
}
|
|
2729
|
+
|
|
388
2730
|
export default (
|
|
389
2731
|
<server>
|
|
390
|
-
<
|
|
391
|
-
<
|
|
392
|
-
<
|
|
393
|
-
|
|
394
|
-
|
|
2732
|
+
<api>
|
|
2733
|
+
<fallback>
|
|
2734
|
+
<error
|
|
2735
|
+
code='noUser'
|
|
2736
|
+
status='notFound'>
|
|
2737
|
+
{data}
|
|
2738
|
+
</error>
|
|
2739
|
+
</fallback>
|
|
2740
|
+
</api>
|
|
395
2741
|
</server>
|
|
396
2742
|
)
|
|
397
2743
|
```
|
|
398
2744
|
|
|
399
|
-
|
|
2745
|
+
Then you get
|
|
2746
|
+
|
|
2747
|
+
*for the previous example*
|
|
2748
|
+
```json
|
|
2749
|
+
{
|
|
2750
|
+
"error": "noUser",
|
|
2751
|
+
"data": {
|
|
2752
|
+
"message": "User not found!"
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
```
|
|
2756
|
+
|
|
2757
|
+
There are some default errors:
|
|
2758
|
+
|
|
2759
|
+
- `undefined` - when you use `<error>` element without `code`.
|
|
2760
|
+
- `requestValidation` - when request data fails schema validation.
|
|
2761
|
+
- `requestBodyContentType` - when cannot parse body.
|
|
2762
|
+
- `unknown` - can because of JSON stringify fail or other errors.
|
|
2763
|
+
|
|
2764
|
+
### \<proxy>
|
|
400
2765
|
|
|
401
|
-
|
|
402
|
-
routers in the same router runs one by one
|
|
403
|
-
independent to result of the previous route.
|
|
2766
|
+
[← back](#run-time)
|
|
404
2767
|
|
|
405
|
-
|
|
2768
|
+
MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
2769
|
+
|
|
2770
|
+
You can easy proxy endpoints to another server/service.
|
|
2771
|
+
|
|
2772
|
+
*src/app.tsx*
|
|
406
2773
|
```typescript jsx
|
|
407
2774
|
export default (
|
|
408
2775
|
<server>
|
|
409
|
-
<
|
|
410
|
-
<
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
2776
|
+
<api>
|
|
2777
|
+
<endpoint
|
|
2778
|
+
path='/test'
|
|
2779
|
+
method='get'>
|
|
2780
|
+
<request>
|
|
2781
|
+
<proxy to='https://...' />
|
|
2782
|
+
</request>
|
|
2783
|
+
</endpoint>
|
|
2784
|
+
<fallback>
|
|
2785
|
+
<proxy to='https://...' />
|
|
2786
|
+
</fallback>
|
|
2787
|
+
</api>
|
|
417
2788
|
</server>
|
|
418
2789
|
)
|
|
419
2790
|
```
|
|
420
2791
|
|
|
421
|
-
|
|
422
|
-
any other path will return `404.html`.
|
|
2792
|
+
### \<redirect>
|
|
423
2793
|
|
|
424
|
-
|
|
2794
|
+
[← back](#run-time)
|
|
425
2795
|
|
|
426
|
-
|
|
2796
|
+
MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
427
2797
|
|
|
2798
|
+
You can redirect users to another resource. It adds `Cache-Control` header by default.
|
|
2799
|
+
|
|
2800
|
+
*src/app.tsx*
|
|
428
2801
|
```typescript jsx
|
|
429
2802
|
export default (
|
|
430
2803
|
<server>
|
|
431
|
-
<
|
|
432
|
-
<
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
2804
|
+
<api>
|
|
2805
|
+
<endpoint
|
|
2806
|
+
path='/test'
|
|
2807
|
+
method='get'>
|
|
2808
|
+
<request>
|
|
2809
|
+
<redirect to='https://...' />
|
|
2810
|
+
</request>
|
|
2811
|
+
</endpoint>
|
|
2812
|
+
<fallback>
|
|
2813
|
+
<redirect to='https://...' />
|
|
2814
|
+
</fallback>
|
|
2815
|
+
</api>
|
|
437
2816
|
</server>
|
|
438
2817
|
)
|
|
439
2818
|
```
|
|
440
2819
|
|
|
441
|
-
|
|
2820
|
+
#### status
|
|
442
2821
|
|
|
443
|
-
|
|
2822
|
+
`<redirect>` element returns status `301` by default.
|
|
2823
|
+
You can change it by `status` property.
|
|
444
2824
|
|
|
2825
|
+
*src/app.tsx*
|
|
445
2826
|
```typescript jsx
|
|
446
2827
|
export default (
|
|
447
2828
|
<server>
|
|
448
|
-
<
|
|
449
|
-
<
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
2829
|
+
<api>
|
|
2830
|
+
<endpoint
|
|
2831
|
+
path='/test'
|
|
2832
|
+
method='get'>
|
|
2833
|
+
<request>
|
|
2834
|
+
<redirect
|
|
2835
|
+
status='found'
|
|
2836
|
+
to='https://...'
|
|
2837
|
+
/>
|
|
2838
|
+
</request>
|
|
2839
|
+
</endpoint>
|
|
2840
|
+
<fallback>
|
|
2841
|
+
<redirect
|
|
2842
|
+
status={303}
|
|
2843
|
+
to='https://...'
|
|
2844
|
+
/>
|
|
2845
|
+
</fallback>
|
|
2846
|
+
</api>
|
|
456
2847
|
</server>
|
|
457
2848
|
)
|
|
458
2849
|
```
|
|
459
2850
|
|
|
460
|
-
|
|
2851
|
+
### \<cms>
|
|
2852
|
+
|
|
2853
|
+
[← back](#run-time)
|
|
461
2854
|
|
|
2855
|
+
MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
2856
|
+
|
|
2857
|
+
`<cms>` helps to return files from a folder by path. It checks files run-time on the server.
|
|
2858
|
+
|
|
2859
|
+
*src/app.tsx*
|
|
462
2860
|
```typescript jsx
|
|
463
2861
|
export default (
|
|
464
2862
|
<server>
|
|
465
|
-
<
|
|
466
|
-
<
|
|
467
|
-
<cms
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
<file path='404.html' />
|
|
471
|
-
</switch>
|
|
472
|
-
</action>
|
|
2863
|
+
<api>
|
|
2864
|
+
<fallback>
|
|
2865
|
+
<cms />
|
|
2866
|
+
</fallback>
|
|
2867
|
+
</api>
|
|
473
2868
|
</server>
|
|
474
2869
|
)
|
|
475
2870
|
```
|
|
476
2871
|
|
|
477
|
-
|
|
478
|
-
|
|
2872
|
+
#### dir
|
|
2873
|
+
|
|
2874
|
+
By default, it looks at project folder.
|
|
2875
|
+
If you try the previous example on [http://localhost/package.json](http://localhost/package.json)
|
|
2876
|
+
you get the project `package.json` file.
|
|
479
2877
|
|
|
2878
|
+
You can change root folder by `dir` property.
|
|
2879
|
+
|
|
2880
|
+
*src/app.tsx*
|
|
480
2881
|
```typescript jsx
|
|
481
2882
|
export default (
|
|
482
2883
|
<server>
|
|
483
|
-
<
|
|
484
|
-
<
|
|
485
|
-
<cms dir='
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
</action>
|
|
2884
|
+
<api>
|
|
2885
|
+
<fallback>
|
|
2886
|
+
<cms dir='src' />
|
|
2887
|
+
</fallback>
|
|
2888
|
+
</api>
|
|
489
2889
|
</server>
|
|
490
2890
|
)
|
|
491
2891
|
```
|
|
492
2892
|
|
|
493
|
-
|
|
494
|
-
|
|
2893
|
+
Now you can try [http://localhost/index.tsx](http://localhost/index.tsx)
|
|
2894
|
+
you get the index file in `src` folder.
|
|
2895
|
+
|
|
2896
|
+
#### prefix
|
|
495
2897
|
|
|
496
|
-
|
|
497
|
-
You can redirect users to another resource.
|
|
2898
|
+
`<cms>` matches full `path`, you should take it into account if you add `prefix` on `<api>`.
|
|
498
2899
|
|
|
2900
|
+
*src/app.tsx*
|
|
499
2901
|
```typescript jsx
|
|
500
2902
|
export default (
|
|
501
2903
|
<server>
|
|
502
|
-
<
|
|
503
|
-
<
|
|
504
|
-
<cms
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
</action>
|
|
2904
|
+
<api prefix='/src'>
|
|
2905
|
+
<fallback>
|
|
2906
|
+
<cms />
|
|
2907
|
+
</fallback>
|
|
2908
|
+
</api>
|
|
508
2909
|
</server>
|
|
509
2910
|
)
|
|
510
2911
|
```
|
|
511
2912
|
|
|
512
|
-
|
|
513
|
-
|
|
2913
|
+
Here you can try [http://localhost/src/index.tsx](http://localhost/src/index.tsx)
|
|
2914
|
+
you get the index file in `src` folder.
|
|
514
2915
|
|
|
2916
|
+
You can reduce the path for matching by prefix property of `<cms>`.
|
|
2917
|
+
|
|
2918
|
+
*src/app.tsx*
|
|
515
2919
|
```typescript jsx
|
|
516
2920
|
export default (
|
|
517
2921
|
<server>
|
|
518
|
-
<
|
|
519
|
-
<
|
|
520
|
-
<cms
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
</action>
|
|
2922
|
+
<api prefix='/api'>
|
|
2923
|
+
<fallback>
|
|
2924
|
+
<cms prefix='/api' />
|
|
2925
|
+
</fallback>
|
|
2926
|
+
</api>
|
|
524
2927
|
</server>
|
|
525
2928
|
)
|
|
526
2929
|
```
|
|
527
2930
|
|
|
528
|
-
|
|
2931
|
+
Now you can try [http://localhost/api/package.json](http://localhost/api/package.json)
|
|
2932
|
+
|
|
2933
|
+
#### children
|
|
529
2934
|
|
|
2935
|
+
You can handle if a file was not found by children elements of `<cms>`.
|
|
2936
|
+
|
|
2937
|
+
*src/app.tsx*
|
|
530
2938
|
```typescript jsx
|
|
531
2939
|
export default (
|
|
532
2940
|
<server>
|
|
533
|
-
<
|
|
534
|
-
<
|
|
535
|
-
<cms
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
2941
|
+
<api prefix='/src'>
|
|
2942
|
+
<fallback>
|
|
2943
|
+
<cms>
|
|
2944
|
+
<error status={404} />
|
|
2945
|
+
</cms>
|
|
2946
|
+
</fallback>
|
|
2947
|
+
</api>
|
|
539
2948
|
</server>
|
|
540
2949
|
)
|
|
541
2950
|
```
|
|
542
2951
|
|
|
543
|
-
|
|
2952
|
+
### \<file>
|
|
2953
|
+
|
|
2954
|
+
[← back](#run-time)
|
|
544
2955
|
|
|
545
|
-
|
|
2956
|
+
It returns a file. MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
546
2957
|
|
|
547
|
-
`
|
|
2958
|
+
It adds `Content-Length` and `Content-Type` automatically.
|
|
2959
|
+
|
|
2960
|
+
It has a REQUIRED property of `path`.
|
|
2961
|
+
|
|
2962
|
+
*src/app.tsx*
|
|
548
2963
|
```typescript jsx
|
|
549
|
-
export
|
|
2964
|
+
export default (
|
|
550
2965
|
<server>
|
|
551
|
-
<
|
|
552
|
-
<
|
|
553
|
-
<
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
</action>
|
|
2966
|
+
<api>
|
|
2967
|
+
<fallback>
|
|
2968
|
+
<file
|
|
2969
|
+
path='package.json'
|
|
2970
|
+
/>
|
|
2971
|
+
</fallback>
|
|
2972
|
+
</api>
|
|
559
2973
|
</server>
|
|
560
2974
|
)
|
|
561
2975
|
```
|
|
562
2976
|
|
|
563
|
-
|
|
2977
|
+
For this example you get `package.json` file of the project on any path except for `/`.
|
|
564
2978
|
|
|
565
|
-
|
|
566
|
-
|
|
2979
|
+
#### children
|
|
2980
|
+
|
|
2981
|
+
You can handle if a file was not found by children elements of `<file>`.
|
|
567
2982
|
|
|
568
|
-
|
|
2983
|
+
*src/app.tsx*
|
|
2984
|
+
```typescript jsx
|
|
2985
|
+
export default (
|
|
2986
|
+
<server>
|
|
2987
|
+
<api prefix='/src'>
|
|
2988
|
+
<fallback>
|
|
2989
|
+
<file path='file_is_not_exist.txt'>
|
|
2990
|
+
<error status={404} />
|
|
2991
|
+
</file>
|
|
2992
|
+
</fallback>
|
|
2993
|
+
</api>
|
|
2994
|
+
</server>
|
|
2995
|
+
)
|
|
569
2996
|
```
|
|
570
2997
|
|
|
571
|
-
|
|
2998
|
+
### \<header>
|
|
572
2999
|
|
|
573
|
-
|
|
574
|
-
import { useChildren } from '@innet/jsx'
|
|
3000
|
+
MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
575
3001
|
|
|
576
|
-
|
|
577
|
-
const children = useChildren()
|
|
3002
|
+
[← back](#run-time)
|
|
578
3003
|
|
|
579
|
-
|
|
580
|
-
<header name='content-type' value='text/html'>
|
|
581
|
-
<html>
|
|
582
|
-
<head>
|
|
583
|
-
<title>{title}</title>
|
|
584
|
-
</head>
|
|
585
|
-
<body>
|
|
586
|
-
{children}
|
|
587
|
-
</body>
|
|
588
|
-
</html>
|
|
589
|
-
</header>
|
|
590
|
-
)
|
|
591
|
-
}
|
|
3004
|
+
You can add an HTTP header into response by `<header>` element.
|
|
592
3005
|
|
|
3006
|
+
*src/app.tsx*
|
|
3007
|
+
```typescript jsx
|
|
593
3008
|
export default (
|
|
594
3009
|
<server>
|
|
595
|
-
<
|
|
596
|
-
<
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
3010
|
+
<api prefix='/src'>
|
|
3011
|
+
<fallback>
|
|
3012
|
+
<header
|
|
3013
|
+
key='Cache-Control'
|
|
3014
|
+
value='no-cache, no-store, must-revalidate'
|
|
3015
|
+
/>
|
|
3016
|
+
<success />
|
|
3017
|
+
</fallback>
|
|
3018
|
+
</api>
|
|
3019
|
+
</server>
|
|
601
3020
|
)
|
|
602
3021
|
```
|
|
603
3022
|
|
|
604
|
-
|
|
3023
|
+
### \<cookie>
|
|
605
3024
|
|
|
606
|
-
|
|
3025
|
+
MUST be placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
607
3026
|
|
|
608
|
-
|
|
609
|
-
If you work on REST API, you can use `success` or `error` as an answer
|
|
3027
|
+
[← back](#run-time)
|
|
610
3028
|
|
|
3029
|
+
You can add/remove a cookie into response by `<cookie>` element.
|
|
3030
|
+
|
|
3031
|
+
*src/app.tsx*
|
|
611
3032
|
```typescript jsx
|
|
612
3033
|
export default (
|
|
613
3034
|
<server>
|
|
614
|
-
<
|
|
615
|
-
<
|
|
616
|
-
|
|
617
|
-
|
|
3035
|
+
<api prefix='/src'>
|
|
3036
|
+
<fallback>
|
|
3037
|
+
<cookie
|
|
3038
|
+
key='token'
|
|
3039
|
+
value='...'
|
|
3040
|
+
/>
|
|
3041
|
+
<cookie
|
|
3042
|
+
key='removedCookie'
|
|
3043
|
+
/>
|
|
3044
|
+
<success />
|
|
3045
|
+
</fallback>
|
|
3046
|
+
</api>
|
|
3047
|
+
</server>
|
|
618
3048
|
)
|
|
619
3049
|
```
|
|
620
3050
|
|
|
621
|
-
|
|
3051
|
+
#### domain
|
|
622
3052
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
const data = {
|
|
626
|
-
posts: []
|
|
627
|
-
}
|
|
3053
|
+
The prop specifies the value for the [Domain Set-Cookie attribute](https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.3).
|
|
3054
|
+
By default, no domain is set, and most clients will consider the cookie to apply to only the current domain.
|
|
628
3055
|
|
|
3056
|
+
*src/app.tsx*
|
|
3057
|
+
```typescript jsx
|
|
629
3058
|
export default (
|
|
630
3059
|
<server>
|
|
631
|
-
<
|
|
632
|
-
<
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
3060
|
+
<api prefix='/src'>
|
|
3061
|
+
<fallback>
|
|
3062
|
+
<cookie
|
|
3063
|
+
domain='.example.com'
|
|
3064
|
+
key='token'
|
|
3065
|
+
value='...'
|
|
3066
|
+
/>
|
|
3067
|
+
<success />
|
|
3068
|
+
</fallback>
|
|
3069
|
+
</api>
|
|
636
3070
|
</server>
|
|
637
3071
|
)
|
|
638
3072
|
```
|
|
639
|
-
You will get `200` status (`ok`), with body equals data.
|
|
640
3073
|
|
|
641
|
-
|
|
642
|
-
You can set status by status prop.
|
|
3074
|
+
#### encode
|
|
643
3075
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
3076
|
+
Specifies a function that will be used to encode a cookie's value. Since value of a cookie has a limited character set (and must be a simple string), this function can be used to encode a value into a string suited for a cookie's value.
|
|
3077
|
+
The default function is the global encodeURIComponent, which will encode a JavaScript string into UTF-8 byte sequences and then URL-encode any that fall outside of the cookie range.
|
|
3078
|
+
|
|
3079
|
+
#### expires
|
|
648
3080
|
|
|
3081
|
+
Specifies the Date object to be the value for the Expires [Set-Cookie attribute](https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.1). By default, no expiration is set, and most clients will consider this a “non-persistent cookie” and will delete it on a condition like exiting a web browser application.
|
|
3082
|
+
Note the [cookie storage model specification](https://datatracker.ietf.org/doc/html/rfc6265#section-5.3) states that if both expires and maxAge are set, then maxAge takes precedence, but it is possible not all clients by obey this, so if both are set, they should point to the same date and time.
|
|
3083
|
+
|
|
3084
|
+
*src/app.tsx*
|
|
3085
|
+
```typescript jsx
|
|
649
3086
|
export default (
|
|
650
3087
|
<server>
|
|
651
|
-
<
|
|
652
|
-
<
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
3088
|
+
<api prefix='/src'>
|
|
3089
|
+
<fallback>
|
|
3090
|
+
<cookie
|
|
3091
|
+
expires={new Date('2050-01-01')}
|
|
3092
|
+
key='token'
|
|
3093
|
+
value='...'
|
|
3094
|
+
/>
|
|
3095
|
+
<success />
|
|
3096
|
+
</fallback>
|
|
3097
|
+
</api>
|
|
3098
|
+
</server>
|
|
657
3099
|
)
|
|
658
3100
|
```
|
|
659
3101
|
|
|
660
|
-
|
|
3102
|
+
#### httpOnly
|
|
661
3103
|
|
|
662
|
-
|
|
3104
|
+
Specifies the boolean value for the [HttpOnly Set-Cookie attribute](https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.6). When truthy, the HttpOnly attribute is set, otherwise it is not. By default, the HttpOnly attribute is not set.
|
|
3105
|
+
Note be careful when setting this to true, as compliant clients will not allow client-side JavaScript to see the cookie in document.cookie.
|
|
663
3106
|
|
|
3107
|
+
*src/app.tsx*
|
|
664
3108
|
```typescript jsx
|
|
665
|
-
const data = {
|
|
666
|
-
id: '123'
|
|
667
|
-
}
|
|
668
|
-
|
|
669
3109
|
export default (
|
|
670
3110
|
<server>
|
|
671
|
-
<
|
|
672
|
-
<
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
3111
|
+
<api prefix='/src'>
|
|
3112
|
+
<fallback>
|
|
3113
|
+
<cookie
|
|
3114
|
+
httpOnly
|
|
3115
|
+
key='token'
|
|
3116
|
+
value='...'
|
|
3117
|
+
/>
|
|
3118
|
+
<success />
|
|
3119
|
+
</fallback>
|
|
3120
|
+
</api>
|
|
3121
|
+
</server>
|
|
677
3122
|
)
|
|
678
3123
|
```
|
|
679
3124
|
|
|
680
|
-
|
|
681
|
-
You can return an error to the user.
|
|
3125
|
+
#### maxAge
|
|
682
3126
|
|
|
3127
|
+
Specifies the number (in seconds) to be the value for the Max-Age Set-Cookie attribute. The given number will be converted to an integer by rounding down. By default, no maximum age is set.
|
|
3128
|
+
Note the [cookie storage model specification](https://datatracker.ietf.org/doc/html/rfc6265#section-5.3) states that if both expires and maxAge are set, then maxAge takes precedence, but it is possible not all clients by obey this, so if both are set, they should point to the same date and time.
|
|
3129
|
+
|
|
3130
|
+
*src/app.tsx*
|
|
683
3131
|
```typescript jsx
|
|
684
3132
|
export default (
|
|
685
3133
|
<server>
|
|
686
|
-
<
|
|
687
|
-
<
|
|
688
|
-
|
|
689
|
-
|
|
3134
|
+
<api prefix='/src'>
|
|
3135
|
+
<fallback>
|
|
3136
|
+
<cookie
|
|
3137
|
+
httpOnly
|
|
3138
|
+
maxAge={9999}
|
|
3139
|
+
key='token'
|
|
3140
|
+
value='...'
|
|
3141
|
+
/>
|
|
3142
|
+
<success />
|
|
3143
|
+
</fallback>
|
|
3144
|
+
</api>
|
|
3145
|
+
</server>
|
|
690
3146
|
)
|
|
691
3147
|
```
|
|
692
3148
|
|
|
693
|
-
|
|
3149
|
+
#### path
|
|
694
3150
|
|
|
695
|
-
|
|
3151
|
+
Specifies the value for the [Path Set-Cookie attribute](https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.4).
|
|
3152
|
+
By default, the path is considered the “default path”.
|
|
696
3153
|
|
|
3154
|
+
*src/app.tsx*
|
|
697
3155
|
```typescript jsx
|
|
698
|
-
const data = {
|
|
699
|
-
message: 'Some error!'
|
|
700
|
-
}
|
|
701
|
-
|
|
702
3156
|
export default (
|
|
703
3157
|
<server>
|
|
704
|
-
<
|
|
705
|
-
<
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
3158
|
+
<api prefix='/src'>
|
|
3159
|
+
<fallback>
|
|
3160
|
+
<cookie
|
|
3161
|
+
httpOnly
|
|
3162
|
+
maxAge={9999}
|
|
3163
|
+
path='/src'
|
|
3164
|
+
key='token'
|
|
3165
|
+
value='...'
|
|
3166
|
+
/>
|
|
3167
|
+
<success />
|
|
3168
|
+
</fallback>
|
|
3169
|
+
</api>
|
|
3170
|
+
</server>
|
|
710
3171
|
)
|
|
711
3172
|
```
|
|
712
3173
|
|
|
713
|
-
|
|
714
|
-
You can change response status by `status` prop.
|
|
3174
|
+
#### priority
|
|
715
3175
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
3176
|
+
Specifies the string to be the value for the «Priority Set-Cookie attribute».
|
|
3177
|
+
|
|
3178
|
+
- `'low'` will set the Priority attribute to Low.
|
|
3179
|
+
- `'medium'` will set the Priority attribute to Medium, the default priority when not set.
|
|
3180
|
+
- `'high'` will set the Priority attribute to High.
|
|
720
3181
|
|
|
3182
|
+
note This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it.
|
|
3183
|
+
|
|
3184
|
+
*src/app.tsx*
|
|
3185
|
+
```typescript jsx
|
|
721
3186
|
export default (
|
|
722
3187
|
<server>
|
|
723
|
-
<
|
|
724
|
-
<
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
3188
|
+
<api prefix='/src'>
|
|
3189
|
+
<fallback>
|
|
3190
|
+
<cookie
|
|
3191
|
+
httpOnly
|
|
3192
|
+
priority='high'
|
|
3193
|
+
path='/src'
|
|
3194
|
+
key='token'
|
|
3195
|
+
value='...'
|
|
3196
|
+
/>
|
|
3197
|
+
<success />
|
|
3198
|
+
</fallback>
|
|
3199
|
+
</api>
|
|
728
3200
|
</server>
|
|
729
3201
|
)
|
|
730
3202
|
```
|
|
731
|
-
Also, you can use a number with the status prop.
|
|
732
3203
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
3204
|
+
#### sameSite
|
|
3205
|
+
|
|
3206
|
+
Specifies the `boolean` or `string` to be the value for the SameSite Set-Cookie attribute.
|
|
3207
|
+
|
|
3208
|
+
- `true` will set the SameSite attribute to Strict for strict same site enforcement.
|
|
3209
|
+
- `false` will not set the SameSite attribute.
|
|
3210
|
+
- `'lax'` will set the SameSite attribute to Lax for lax same site enforcement.
|
|
3211
|
+
- `'strict'` will set the SameSite attribute to Strict for strict same site enforcement.
|
|
3212
|
+
- `'none'` will set the SameSite attribute to None for an explicit cross-site cookie.
|
|
3213
|
+
|
|
3214
|
+
note This is an attribute that has not yet been fully standardized, and may change in the future.
|
|
3215
|
+
This also means many clients may ignore this attribute until they understand it.
|
|
737
3216
|
|
|
3217
|
+
*src/app.tsx*
|
|
3218
|
+
```typescript jsx
|
|
738
3219
|
export default (
|
|
739
3220
|
<server>
|
|
740
|
-
<
|
|
741
|
-
<
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
3221
|
+
<api prefix='/src'>
|
|
3222
|
+
<fallback>
|
|
3223
|
+
<cookie
|
|
3224
|
+
httpOnly
|
|
3225
|
+
sameSite
|
|
3226
|
+
priority='high'
|
|
3227
|
+
path='/src'
|
|
3228
|
+
key='token'
|
|
3229
|
+
value='...'
|
|
3230
|
+
/>
|
|
3231
|
+
<success />
|
|
3232
|
+
</fallback>
|
|
3233
|
+
</api>
|
|
745
3234
|
</server>
|
|
746
3235
|
)
|
|
747
3236
|
```
|
|
748
3237
|
|
|
749
|
-
|
|
750
|
-
You can set cookie by `cookie` element.
|
|
3238
|
+
#### secure
|
|
751
3239
|
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
<success />
|
|
756
|
-
</cookie>
|
|
757
|
-
)
|
|
3240
|
+
Specifies the boolean value for the [Secure Set-Cookie attribute](https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.5).
|
|
3241
|
+
When truthy, the Secure attribute is set, otherwise it is not.
|
|
3242
|
+
By default, the Secure attribute is not set.
|
|
758
3243
|
|
|
3244
|
+
Note be careful when setting this to true, as compliant clients will not send the cookie back to the server in the future if the browser does not have an HTTPS connection.
|
|
3245
|
+
|
|
3246
|
+
*src/app.tsx*
|
|
3247
|
+
```typescript jsx
|
|
759
3248
|
export default (
|
|
760
3249
|
<server>
|
|
761
|
-
<
|
|
762
|
-
<
|
|
763
|
-
|
|
764
|
-
|
|
3250
|
+
<api prefix='/src'>
|
|
3251
|
+
<fallback>
|
|
3252
|
+
<cookie
|
|
3253
|
+
httpOnly
|
|
3254
|
+
secure
|
|
3255
|
+
key='token'
|
|
3256
|
+
value='...'
|
|
3257
|
+
/>
|
|
3258
|
+
<success />
|
|
3259
|
+
</fallback>
|
|
3260
|
+
</api>
|
|
3261
|
+
</server>
|
|
3262
|
+
)
|
|
3263
|
+
```
|
|
3264
|
+
|
|
3265
|
+
## Components
|
|
3266
|
+
|
|
3267
|
+
[← back](#index)
|
|
3268
|
+
|
|
3269
|
+
Component is a function which returns content that, like, placed instead of the component.
|
|
3270
|
+
Like you can inject a plugin between elements.
|
|
3271
|
+
Components are from [@innet/jsx](https://www.npmjs.com/package/@innet/jsx).
|
|
3272
|
+
|
|
3273
|
+
*src/SetToken.tsx*
|
|
3274
|
+
```typescript jsx
|
|
3275
|
+
export const SetToken = ({ value }) => (
|
|
3276
|
+
<cookie
|
|
3277
|
+
httpOnly
|
|
3278
|
+
secure
|
|
3279
|
+
key='token'
|
|
3280
|
+
value={value}
|
|
3281
|
+
/>
|
|
765
3282
|
)
|
|
766
3283
|
```
|
|
767
3284
|
|
|
768
|
-
|
|
3285
|
+
and then you can use it inside `app.tsx`.
|
|
769
3286
|
|
|
3287
|
+
*src/app.tsx*
|
|
770
3288
|
```typescript jsx
|
|
3289
|
+
import { SetToken } from './SetToken'
|
|
3290
|
+
|
|
771
3291
|
export default (
|
|
772
3292
|
<server>
|
|
773
|
-
<
|
|
774
|
-
<
|
|
3293
|
+
<api prefix='/src'>
|
|
3294
|
+
<fallback>
|
|
3295
|
+
<SetToken
|
|
3296
|
+
value='...'
|
|
3297
|
+
/>
|
|
775
3298
|
<success />
|
|
776
|
-
</
|
|
777
|
-
</
|
|
778
|
-
</server>
|
|
3299
|
+
</fallback>
|
|
3300
|
+
</api>
|
|
3301
|
+
</server>
|
|
779
3302
|
)
|
|
780
3303
|
```
|
|
781
3304
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
3305
|
+
You can use [hooks](#hooks) inside components.
|
|
3306
|
+
|
|
3307
|
+
## Hooks
|
|
785
3308
|
|
|
786
|
-
|
|
3309
|
+
Hook functions give you all features to control parent element functionality.
|
|
3310
|
+
|
|
3311
|
+
[← back](#index)
|
|
3312
|
+
|
|
3313
|
+
[useServer](#useserver)
|
|
3314
|
+
[useRequest](#userequest)
|
|
3315
|
+
[useResponse](#useresponse)
|
|
3316
|
+
[useHeaders](#useheaders)
|
|
3317
|
+
[useCookies](#usecookies)
|
|
3318
|
+
[usePath](#usepath)
|
|
3319
|
+
[useParams](#useparams)
|
|
3320
|
+
[useSearch](#usesearch)
|
|
3321
|
+
[useBody](#usebody)
|
|
3322
|
+
|
|
3323
|
+
---
|
|
3324
|
+
|
|
3325
|
+
### useServer
|
|
3326
|
+
|
|
3327
|
+
[← back](#hooks)
|
|
3328
|
+
|
|
3329
|
+
This hook MUST be used in a component placed in `<server>`.
|
|
3330
|
+
This hook returns current http(s) server instance.
|
|
3331
|
+
|
|
3332
|
+
*src/Component.tsx*
|
|
787
3333
|
|
|
788
3334
|
```typescript jsx
|
|
789
|
-
import {
|
|
3335
|
+
import { useServer } from '@innet/sever'
|
|
3336
|
+
|
|
3337
|
+
export function Component () {
|
|
3338
|
+
const server = useServer()
|
|
790
3339
|
|
|
791
|
-
|
|
792
|
-
const { req, res } = useAction()
|
|
3340
|
+
console.log(server)
|
|
793
3341
|
|
|
794
|
-
|
|
3342
|
+
return <success />
|
|
795
3343
|
}
|
|
796
3344
|
```
|
|
797
3345
|
|
|
798
|
-
###
|
|
799
|
-
|
|
3346
|
+
### useRequest
|
|
3347
|
+
|
|
3348
|
+
[← back](#hooks)
|
|
3349
|
+
|
|
3350
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
3351
|
+
This hook returns current request instance.
|
|
3352
|
+
|
|
3353
|
+
*src/Component.tsx*
|
|
800
3354
|
|
|
801
3355
|
```typescript jsx
|
|
802
|
-
import {
|
|
3356
|
+
import { useRequest } from '@innet/sever'
|
|
3357
|
+
|
|
3358
|
+
export function Component () {
|
|
3359
|
+
const request = useRequest()
|
|
803
3360
|
|
|
804
|
-
|
|
805
|
-
const { cookies } = useAction()
|
|
3361
|
+
console.log(request)
|
|
806
3362
|
|
|
807
|
-
return <success
|
|
3363
|
+
return <success />
|
|
808
3364
|
}
|
|
809
3365
|
```
|
|
810
3366
|
|
|
811
|
-
###
|
|
812
|
-
|
|
3367
|
+
### useResponse
|
|
3368
|
+
|
|
3369
|
+
[← back](#hooks)
|
|
3370
|
+
|
|
3371
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
3372
|
+
This hook returns current response instance.
|
|
3373
|
+
|
|
3374
|
+
*src/Component.tsx*
|
|
813
3375
|
|
|
814
3376
|
```typescript jsx
|
|
815
|
-
import {
|
|
3377
|
+
import { useResponse } from '@innet/sever'
|
|
3378
|
+
|
|
3379
|
+
export function Component () {
|
|
3380
|
+
const response = useResponse()
|
|
816
3381
|
|
|
817
|
-
|
|
818
|
-
const action = useAction()
|
|
3382
|
+
console.log(response)
|
|
819
3383
|
|
|
820
|
-
|
|
3384
|
+
return <success />
|
|
821
3385
|
}
|
|
822
3386
|
```
|
|
823
3387
|
|
|
824
|
-
###
|
|
825
|
-
|
|
3388
|
+
### useHeaders
|
|
3389
|
+
|
|
3390
|
+
[← back](#hooks)
|
|
3391
|
+
|
|
3392
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
3393
|
+
This hook returns current request headers object.
|
|
3394
|
+
|
|
3395
|
+
*src/Component.tsx*
|
|
826
3396
|
|
|
827
3397
|
```typescript jsx
|
|
828
|
-
import {
|
|
3398
|
+
import { useHeaders } from '@innet/sever'
|
|
829
3399
|
|
|
830
|
-
function
|
|
831
|
-
const
|
|
3400
|
+
export function Component () {
|
|
3401
|
+
const headers = useHeaders()
|
|
832
3402
|
|
|
833
|
-
return
|
|
3403
|
+
return <success>{{ headers }}</success>
|
|
834
3404
|
}
|
|
835
3405
|
```
|
|
836
3406
|
|
|
837
|
-
###
|
|
838
|
-
|
|
3407
|
+
### useCookies
|
|
3408
|
+
|
|
3409
|
+
[← back](#hooks)
|
|
3410
|
+
|
|
3411
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
3412
|
+
This hook returns current request cookies object.
|
|
3413
|
+
|
|
3414
|
+
*src/Component.tsx*
|
|
839
3415
|
|
|
840
3416
|
```typescript jsx
|
|
841
|
-
import {
|
|
3417
|
+
import { useCookies } from '@innet/sever'
|
|
842
3418
|
|
|
843
|
-
function
|
|
844
|
-
const
|
|
3419
|
+
export function Component () {
|
|
3420
|
+
const cookies = useCookies()
|
|
845
3421
|
|
|
846
|
-
return <success>{
|
|
3422
|
+
return <success>{{ cookies }}</success>
|
|
847
3423
|
}
|
|
848
3424
|
```
|
|
849
3425
|
|
|
850
|
-
###
|
|
851
|
-
|
|
3426
|
+
### usePath
|
|
3427
|
+
|
|
3428
|
+
[← back](#hooks)
|
|
3429
|
+
|
|
3430
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
3431
|
+
This hook returns current request URL path as a `string`.
|
|
3432
|
+
|
|
3433
|
+
*src/Component.tsx*
|
|
852
3434
|
|
|
853
3435
|
```typescript jsx
|
|
854
|
-
import {
|
|
3436
|
+
import { usePath } from '@innet/sever'
|
|
855
3437
|
|
|
856
|
-
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
await action.parseBody()
|
|
3438
|
+
export function Component () {
|
|
3439
|
+
const path = usePath()
|
|
860
3440
|
|
|
861
|
-
return <success>{
|
|
3441
|
+
return <success>{{ path }}</success>
|
|
862
3442
|
}
|
|
863
3443
|
```
|
|
864
3444
|
|
|
865
|
-
###
|
|
866
|
-
|
|
3445
|
+
### useParams
|
|
3446
|
+
|
|
3447
|
+
[← back](#hooks)
|
|
3448
|
+
|
|
3449
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
3450
|
+
This hook returns an object of URL params you set by [\<param>](#param).
|
|
867
3451
|
|
|
3452
|
+
*src/Component.tsx*
|
|
868
3453
|
```typescript jsx
|
|
869
|
-
import {
|
|
3454
|
+
import { useParams } from '@innet/sever'
|
|
870
3455
|
|
|
871
|
-
|
|
872
|
-
const
|
|
873
|
-
|
|
874
|
-
await action.parseBody()
|
|
3456
|
+
export function Component () {
|
|
3457
|
+
const params = useParams()
|
|
875
3458
|
|
|
876
|
-
return <success>{
|
|
3459
|
+
return <success>{params}</success>
|
|
877
3460
|
}
|
|
878
3461
|
```
|
|
879
3462
|
|
|
880
|
-
|
|
3463
|
+
### useSearch
|
|
881
3464
|
|
|
882
|
-
|
|
3465
|
+
[← back](#hooks)
|
|
883
3466
|
|
|
3467
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
3468
|
+
This hook returns an object of URL query params.
|
|
3469
|
+
|
|
3470
|
+
*src/Component.tsx*
|
|
884
3471
|
```typescript jsx
|
|
885
|
-
import {
|
|
3472
|
+
import { useSearch } from '@innet/sever'
|
|
886
3473
|
|
|
887
|
-
function
|
|
888
|
-
const
|
|
3474
|
+
export function Component () {
|
|
3475
|
+
const search = useSearch()
|
|
889
3476
|
|
|
890
|
-
return <success>{
|
|
3477
|
+
return <success>{search}</success>
|
|
891
3478
|
}
|
|
892
3479
|
```
|
|
893
3480
|
|
|
894
|
-
|
|
3481
|
+
### useBody
|
|
3482
|
+
|
|
3483
|
+
[← back](#hooks)
|
|
3484
|
+
|
|
3485
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
3486
|
+
This hook returns current request body.
|
|
895
3487
|
|
|
3488
|
+
*src/Component.tsx*
|
|
896
3489
|
```typescript jsx
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
<Router />
|
|
902
|
-
</router>
|
|
903
|
-
</action>
|
|
904
|
-
</server>
|
|
905
|
-
)
|
|
906
|
-
```
|
|
3490
|
+
import { useBody } from '@innet/sever'
|
|
3491
|
+
|
|
3492
|
+
export function Component () {
|
|
3493
|
+
const body = useBody()
|
|
907
3494
|
|
|
908
|
-
|
|
3495
|
+
return <success>{body}</success>
|
|
3496
|
+
}
|
|
3497
|
+
```
|
|
909
3498
|
|
|
910
3499
|
## Issues
|
|
911
3500
|
If you find a bug or have a suggestion, please file an issue on [GitHub](https://github.com/d8corp/innet-server/issues).
|