How to use the @airtasker/spot.endpoint function in @airtasker/spot

To help you get started, we’ve selected a few @airtasker/spot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github airtasker / spot / lib / src / testing / __examples__ / single-provider-state.ts View on Github external
import {
  api,
  body,
  endpoint,
  Integer,
  pathParams,
  request,
  response,
  String,
  test
} from "@airtasker/spot";

@api({ name: "company-api" })
class CompanyApi {}

@endpoint({
  method: "GET",
  path: "/companies/:companyId"
})
class GetCompany {
  @request
  request(
    @pathParams
    pathParams: {
      companyId: String;
    }
  ) {}

  @response({ status: 200 })
  successResponse(@body body: CompanyBody) {}

  @test({
github airtasker / spot / lib / src / neu / parsers / __spec-examples__ / endpoint.ts View on Github external
property: string;
    },
    @body body: string
  ) {}

  @response({ status: 200 })
  response(
    @headers
    headers: {
      property: string;
    },
    @body body: string
  ) {}
}

@endpoint({
  method: "GET",
  path: "/path"
})
class MinimalEndpointClass {}

@draft
@endpoint({
  method: "GET",
  path: "/path"
})
class DraftEndpointClass {}

@endpoint({
  method: "GET",
  path: "/path",
  tags: ["  "]
github airtasker / spot / lib / src / __examples__ / contract.ts View on Github external
lastName: "Snow",
          age: 15,
          email: "johnsnow@spot.com",
          address: "some address"
        }
      }
    },
    response: {
      status: 201
    }
  })
  successResponseTest() {}
}

/** Creates a user in a company */
@endpoint({
  method: "GET",
  path: "/company/:companyId",
  tags: ["Company"]
})
class GetCompany {
  @request
  request(
    @pathParams
    pathParams: {
      /** company identifier */
      companyId: String;
    },
    @headers
    headers: {
      /** Auth Header */
      "x-id": number;
github airtasker / spot / lib / src / neu / parsers / __spec-examples__ / endpoint.ts View on Github external
import {
  body,
  defaultResponse,
  draft,
  endpoint,
  headers,
  pathParams,
  queryParams,
  request,
  response
} from "@airtasker/spot";

class NotEndpointClass {}

/** endpoint description */
@endpoint({
  method: "POST",
  path: "/path/:pathParam/nest",
  tags: ["tag1", "tag2"]
})
class EndpointClass {
  @request
  request(
    @headers
    headers: {
      property: string;
    },
    @pathParams
    pathParams: {
      pathParam: string;
    },
    @queryParams
github airtasker / spot / examples / src / single-file / single-file-api.ts View on Github external
header,
  Int32,
  Int64,
  Optional,
  pathParam,
  queryParam,
  request,
  response,
  specificError
} from "@airtasker/spot";

@api({
  name: "My API"
})
export class Api {
  @endpoint({
    method: "POST",
    path: "/users/create",
    description: "This is an endpoint to create a user",
    tags: ["users"]
  })
  createUser(
    @request req: CreateUserRequest,
    @header({
      name: "Authorization",
      description: "This is the authorization token"
    })
    authToken: Optional
  ): CreateUserResponse {
    return response();
  }
github airtasker / spot / lib / src / neu / parsers / __spec-examples__ / endpoint.ts View on Github external
@endpoint({
  method: "GET",
  path: "/path/:dynamic"
})
class EndpointWithExtraPathParam {
  @request
  request(
    @pathParams
    pathParams: {
      dynamic: string;
      nested: string;
    }
  ) {}
}

@endpoint({
  method: "GET",
  path: "/path"
})
class EndpointWithDuplicateResponseStatus {
  @response({
    status: 200
  })
  responseOne() {}

  @response({
    status: 200
  })
  responseTwo() {}
}
github airtasker / spot / lib / src / neu / parsers / __spec-examples__ / endpoint.ts View on Github external
}

@endpoint({
  method: "GET",
  path: "/path"
})
class MinimalEndpointClass {}

@draft
@endpoint({
  method: "GET",
  path: "/path"
})
class DraftEndpointClass {}

@endpoint({
  method: "GET",
  path: "/path",
  tags: ["  "]
})
class EndpointWithEmptyTag {}

@endpoint({
  method: "GET",
  path: "/path",
  tags: ["tag", "tag"]
})
class EndpointWithDuplicateTag {}

@endpoint({
  method: "GET",
  path: "/path/:dynamic/path/:dynamic"
github airtasker / spot / lib / src / neu / parsers / __spec-examples__ / contracts / contract.ts View on Github external
/** contract description */
@api({ name: "contract" })
@config({
  paramSerializationStrategy: {
    query: {
      array: "comma"
    }
  }
})
class Contract {
  @securityHeader
  "security-header": String;
}

@endpoint({ method: "GET", path: "/path/:param/nest" })
class GetEndpoint {
  @request
  request(
    @pathParams
    pathParams: {
      param: String;
    },
    @headers
    headers: {
      header: String;
    },
    @queryParams
    queryParams: {
      param: String;
    }
  ) {}
github airtasker / spot / examples / src / multi-file / endpoints / delete-user.ts View on Github external
import {
  endpoint,
  genericError,
  header,
  Int64,
  pathParam,
  response,
  specificError
} from "@airtasker/spot";
import { BaseError, ForbiddenError } from "../errors";

export class DeleteUser {
  @endpoint({
    method: "DELETE",
    path: "/users/:userId-confirmed",
    tags: ["users"]
  })
  @genericError()
  @specificError({
    name: "forbidden",
    statusCode: 403
  })
  deleteUser(
    @pathParam() userId: Int64,
    @header({
      name: "Authorization"
    })
    authToken: string
  ): null {
github airtasker / spot / examples / src / multi-file / endpoints / create-user.ts View on Github external
import { endpoint, header, Optional, request, response } from "@airtasker/spot";
import { CreateUserRequest, CreateUserResponse } from "../models";

export class CreateUser {
  @endpoint({
    method: "POST",
    path: "/users/create",
    description: "This is an endpoint to create a user",
    tags: ["users"]
  })
  createUser(
    @request req: CreateUserRequest,
    @header({
      name: "Authorization",
      description: "This is the authorization token"
    })
    authToken: Optional
  ): CreateUserResponse {
    return response();
  }
}

@airtasker/spot

**Spot** (_"Single Point Of Truth"_) is a concise, developer-friendly way to describe your API contract.

MIT
Latest version published 5 months ago

Package Health Score

72 / 100
Full package analysis

Similar packages