Functions API reference
This page provides a full reference of the Netlify Functions API.
# Netlify-specific Context
object
The Context
object exposes the following properties:
account
: an object containing Netlify team account information with the following property:id
: unique ID of the team that the site and function belong to.
cookies
: a simplified interface for reading and storing cookies:cookies.get(name)
: reads a cookie with a given name from the incoming request.cookies.set(options)
: sets a cookie on the outgoing response, using the same format as theoptions
value in theCookieStore.set
web standard.cookies.delete(name)
orcookies.delete(options)
: adds an instruction to the outgoing response for the client to delete a cookie. Following theCookieStore.delete
web standard, accepts a string representing the name of the cookie, or an options object.Setting cookies across subdomains only works for custom domains
netlify.app
is listed in the Mozilla Foundation’s Public Suffix List, which prevents setting cookies across subdomains. You can only set a cookie for all subdomains if your site uses a custom domain instead ofyoursitename.netlify.app
.
deploy
: an object containing Netlify deploy information with the following property:context
: the context of the deploy that the function belongs to.id
: unique ID of the deploy that the function belongs to.published
: a boolean that indicates whether or not the function belongs to the current published deploy.
geo
: an object containing geolocation data for the client with the following properties:city
: name of the city.country
:code
: ISO 3166 code for the country.name
: name of the country.
latitude
: latitude of the location.longitude
: longitude of the location.subdivision
:code
: ISO 3166 code for the country subdivision.name
: name of the country subdivision.
timezone
: timezone of the location.postalCode
: postal (zip) code of the location. We support all regional formats, so the format will vary.
ip
: a string containing the client IP address.requestId
: a string containing the Netlify request ID; for example,01FDWR77JMF2DA1CHF5YA6H07C
.server
: an object containing server metadata with the following property:region
: the region code where the deployment is running; for example,us-east-1
.
site
: an object containing Netlify site metadata with the following properties:id
: unique ID for the site; for example,1d01c0c0-4554-4747-93b8-34ce3448ab95
.name
: name of the site, its Netlify subdomain; for example,petsof
.url
: URL representing the main address to your site. It can be either a Netlify subdomain or your own custom domain if you set one; for example,https://petsof.netlify.app
orhttps://www.petsofnetlify.com
.
# Netlify
global object
The Netlify
global object exposes the following properties:
context
: the Netlify-specificcontext
object.This property is scope-dependent
The context object is only available when
Netlify.context
is accessed from within the scope of a function handler or one of its child scopes. If accessed from somewhere else, like the global scope, it returnsnull
.env
: an object providing access to environment variables with the following properties:delete(name)
: in the context of the invocation, deletes an environment variable with a given name.get(name)
: returns the string value of an environment variable with a given name; if the environment variable is not defined,undefined
is returned.has(name)
: returns a boolean value containingtrue
if an environment variable with a given name exists, andfalse
otherwise.set(name, value)
: in the context of the invocation, sets an environment variable with a given name and value.toObject()
: returns a plain object containing all the environment variables and their values.
Did you find this doc useful?
Your feedback helps us improve our docs.