Skip to content

Create POST endpoint

NOTE

Documentation in development. With the intention of being available soon. If you want to collaborate with the documentation you can do so here

Usage

ts
import { 
Route
} from 'backan'
const
id
= 'form'
const
route
= new
Route
( {
path
:
id
} )
const {
validation
,
response
,
} =
route
route
.
add
(
{
method
: 'post',
path
: '/',
request
: {
body
: {
content
: { 'multipart/form-data' : {
schema
:
validation
.
object
( {
foo
:
validation
.
string
(),
bar
:
validation
.
string
(),
image
:
validation
.
instanceof
(
File
).
or
(
validation
.
string
() ).
openapi
( {
type
: 'string',
format
: 'binary',
} ), } ) .
openapi
( {
required
: [ 'foo' ] } ) } } } },
responses
: {
200 :
response
.
responseJSONSuccess
(
validation
.
object
( {
foo
:
validation
.
string
(),
bar
:
validation
.
string
().
nullable
(),
image
:
validation
.
string
().
nullable
(),
} ) ), 400 :
response
.
responseJSONError400
,
500 :
response
.
responseJSONError500
,
},
tags
: [
id
],
}, async
c
=> {
const {
foo
,
bar
,
image
,
} =
c
.
req
.
valid
( 'form' )
if (
image
instanceof
File
) {
// save file code here } return
c
.
json
(
{
foo
,
bar
,
image
:
image
instanceof
File
?
image
.
name
: null,
}, 200, ) }, ) export default
route