How to use @airtasker/spot - 10 common examples

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 / examples / src / single-file / single-file-api.ts View on Github external
})
  getUser(
    @pathParam({ description: "User unique identifier" }) userId: Int64
  ): Promise<{
    name: string;
    age?: Float;
  }> {
    return response();
  }

  @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 {
    return response();
  }
}

// Requests and responses.
github airtasker / spot / examples / src / single-file / single-file-api.ts View on Github external
getUser(
    @pathParam({ description: "User unique identifier" }) userId: Int64
  ): Promise<{
    name: string;
    age?: Float;
  }> {
    return response();
  }

  @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 {
    return response();
  }
}

// Requests and responses.
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 / testing / __examples__ / draft-endpoint.ts View on Github external
test
} from "@airtasker/spot";

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

@draft
@endpoint({
  method: "POST",
  path: "/companies"
})
class CreateCompany {
  @request
  request(@body body: CreateCompanyRequestBody) {}

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

  @test({
    request: {
      body: {
        name: "My Company",
        private: true
      }
    },
    response: {
      status: 201
    }
  })
  successResponseTest() {}
}
github airtasker / spot / lib / src / testing / __examples__ / default-response.ts View on Github external
String,
  test
} from "@airtasker/spot";

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

@endpoint({
  method: "POST",
  path: "/companies"
})
class CreateCompany {
  @request
  request(@body body: CreateCompanyRequestBody) {}

  @response({ status: 201 })
  successResponse(
    @headers
    headers: {
      Location: String;
    },
    @body body: CompanyBody
  ) {}

  @defaultResponse
  defaultResponse(@body body: DefaultErrorBody) {}

  @test(
    {
      request: {
        body: {
          private: true
github airtasker / spot / lib / src / testing / __examples__ / object-query-param.ts View on Github external
class CompanyApi {}

@endpoint({
  method: "GET",
  path: "/companies"
})
class GetCompanies {
  @request
  request(
    @queryParams
    queryParam: {
      profile?: { name: String };
    }
  ) {}

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

  @test({
    request: {
      queryParams: {
        profile: {
          name: "testname"
        }
      }
    },
    response: {
      status: 200
    }
  })
  successResponseTest() {}
}
github airtasker / spot / lib / src / testing / __examples__ / multiple-tests.ts View on Github external
String,
  test
} from "@airtasker/spot";

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

@endpoint({
  method: "POST",
  path: "/companies"
})
class CreateCompany {
  @request
  request(@body body: CreateCompanyRequestBody) {}

  @response({ status: 201 })
  successResponse(
    @headers
    headers: {
      Location: String;
    },
    @body body: CompanyBody
  ) {}

  @response({ status: 400 })
  badRequestResponse(@body body: ErrorBody) {}

  @test({
    request: {
      body: {
        name: "My Company",
        private: true
github airtasker / spot / lib / src / testing / __examples__ / draft-endpoint.ts View on Github external
import {
  api,
  body,
  draft,
  endpoint,
  headers,
  request,
  response,
  String,
  test
} from "@airtasker/spot";

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

@draft
@endpoint({
  method: "POST",
  path: "/companies"
})
class CreateCompany {
  @request
  request(@body body: CreateCompanyRequestBody) {}

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

  @test({
    request: {
github airtasker / spot / lib / src / testing / __examples__ / default-response.ts View on Github external
@request
  request(@body body: CreateCompanyRequestBody) {}

  @response({ status: 201 })
  successResponse(
    @headers
    headers: {
      Location: String;
    },
    @body body: CompanyBody
  ) {}

  @defaultResponse
  defaultResponse(@body body: DefaultErrorBody) {}

  @test(
    {
      request: {
        body: {
          private: true
        }
      },
      response: {
        status: 400
      }
    },
    { allowInvalidRequest: true }
  )
  defaultResponseTest() {}
}

interface CreateCompanyRequestBody {
github airtasker / spot / lib / src / testing / __examples__ / draft-endpoint.ts View on Github external
@api({ name: "company-api" })
class CompanyApi {}

@draft
@endpoint({
  method: "POST",
  path: "/companies"
})
class CreateCompany {
  @request
  request(@body body: CreateCompanyRequestBody) {}

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

  @test({
    request: {
      body: {
        name: "My Company",
        private: true
      }
    },
    response: {
      status: 201
    }
  })
  successResponseTest() {}
}

interface CreateCompanyRequestBody {
  name: String;
  private: boolean;

@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

74 / 100
Full package analysis

Similar packages