Skip to content
On this page
netzo/apis/cloudflare

Cloudflare

Cloudflare is a web infrastructure and website security company, providing content delivery network services, DDoS mitigation, Internet security, and distributed domain name server services.

  • labels: security, networking, dns, cdn, web-performance
  • authentication: apiKey

Usage

ts
import { cloudflare } from 'https://deno.land/x/netzo/apis/cloudflare/mod.ts'

const { api } = cloudflare({
  apiKey: Deno.env.get('CLOUDFLARE_API_KEY')
})
import { cloudflare } from 'https://deno.land/x/netzo/apis/cloudflare/mod.ts'

const { api } = cloudflare({
  apiKey: Deno.env.get('CLOUDFLARE_API_KEY')
})

Configuration

The cloudfare factory function expects an object with the following, and returns an object with an HTTP client api.

ParamTypeDefaultDescription
apiKeystringDeno.env.get('CLOUDFLARE_API_KEY')the api key to use for authentication

Refer to the API documentation to get the required information.

Examples

The following examples assume you have created an api client instance. Refer to the type definitions for all exported types to pass to the api client for typed responses.

Find organizations

Find all organizations the user is associated with that match the query.

ts
import type { Organizations, QueryOrganizations } from 'netzo/apis/cloudflare/types.ts'

const query: QueryOrganizations = {}
const result = await api.user.organizations.get<Organizations>(query)
const resultData = result.result
import type { Organizations, QueryOrganizations } from 'netzo/apis/cloudflare/types.ts'

const query: QueryOrganizations = {}
const result = await api.user.organizations.get<Organizations>(query)
const resultData = result.result

Find zones

Find all your zones that match the query.

ts
import type { QueryZones, Zones } from 'netzo/apis/cloudflare/types.ts'

const query: QueryZones = {}
const result = await api.zones.get<Zones>(query)
const resultData = result.result
import type { QueryZones, Zones } from 'netzo/apis/cloudflare/types.ts'

const query: QueryZones = {}
const result = await api.zones.get<Zones>(query)
const resultData = result.result

Add zone

Add a new zone.

ts
import type { DataAddZone, Zone } from 'netzo/apis/cloudflare/types.ts'

const data: DataAddZone = {
  account: { id: ZONE_ID },
  name: DOMAIN_NAME
}
const result = await api.zones.post<Zone>(data)
const resultData = result.result
import type { DataAddZone, Zone } from 'netzo/apis/cloudflare/types.ts'

const data: DataAddZone = {
  account: { id: ZONE_ID },
  name: DOMAIN_NAME
}
const result = await api.zones.post<Zone>(data)
const resultData = result.result

Delete zone

Delete a zone by id.

ts
import type { DeleteResult } from 'netzo/apis/cloudflare/types.ts'

const result = await api.zones[ZONE_ID].delete<DeleteResult>()
const resultData = result.result
import type { DeleteResult } from 'netzo/apis/cloudflare/types.ts'

const result = await api.zones[ZONE_ID].delete<DeleteResult>()
const resultData = result.result

References