# Modules

ZITADEL provides the following modules.

## [HTTP](/content/docs/apis/actions/modules#http/index.html)

This module provides functionality to call REST APIs.

### [Import](/content/docs/apis/actions/modules#import/index.html)

```javascript
let http = require('zitadel/http')
```

### [`fetch()` function](/content/docs/apis/actions/modules#fetch-function/index.html)

This function allows to call HTTP servers. The function does NOT fulfil the [Fetch API specification](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).

#### [Parameters](/content/docs/apis/actions/modules#parameters/index.html)

- `url` _string_
- `options` **Optional**, containing custom settings that you want to apply to the request.
  - `headers`
    Overwrites the default headers. One of the following types
    - _map[string] string_
      The value is split into separate values after each comma `,`.
    - _map[string] Array of string_
      The value is a string array
    - default:
      - `Content-Type`: `application/json`
      - `Accept`: `application/json`
  - `method`
    The request method. Allowed values are `GET`, `POST`, `PUT`, `DELETE`
  - `body` _Object_
    JSON representation

#### [Response](/content/docs/apis/actions/modules#response/index.html)

If the request was invalid, an error will be thrown; otherwise, a Response object will be returned.

The object has the following fields and methods:

- `status` _number_
  Status code of response
- `body` _string_
  Return value
- `json()` _Object_
  Returns the body as JSON object, or throws an error if the body is not a json object.
- `text()` _string_
  Returns the body

### [Example](/content/docs/apis/actions/modules#example/index.html)

```javascript
let http = require('zitadel/http')
let logger = require("zitadel/log")
function make_api_call(ctx, api) {
    var user = http.fetch('API_URL', {
        method: 'POST',
        body: {
            "name": "user 1"
        }
    }).json();
    logger.log(user.id);
}
```

## [Log](/content/docs/apis/actions/modules#log/index.html)

The log module provides you with the functionality to log to stdout.

### [Import](/content/docs/apis/actions/modules#import/index.html)

```javascript
   let logger = require("zitadel/log")
```

### [`log()`, `warn()`, `error()` function](/content/docs/apis/actions/modules#log-warn-error-function/index.html)

The logger offers three distinct log levels (info, warn, and error) to effectively communicate messages based on their severity, enhancing debugging and troubleshooting efficiency.
Use the function that reflects your log level.

- log()
- warn()
- error()

### [Example](/content/docs/apis/actions/modules#example/index.html)

```javascript
logger.log("This is an info log.")

logger.warn("This is a warn log.")

logger.error("This is an error log.")
```

#### [Parameters](/content/docs/apis/actions/modules#parameters/index.html)

- `msg` _string_
  The message you want to print out.

## [UUID](/content/docs/apis/actions/modules#uuid/index.html)

This module provides functionality to generate a UUID

### [Import](/content/docs/apis/actions/modules#import/index.html)

```javascript
    let uuid = require("zitadel/uuid")
```

### [`uuid.vX()` function](/content/docs/apis/actions/modules#uuid-v-x-function/index.html)

This function generates a UUID using [google/uuid](https://github.com/google/uuid). `vX` allows to define the UUID version:

- `uuid.v1()` _string_
  Generates a UUID version 1, based on date-time and MAC address
- `uuid.v3(namespace, data)` _string_
  Generates a UUID version 3, based on the provided namespace using MD5
- `uuid.v4()` _string_
  Generates a UUID version 4, which is randomly generated
- `uuid.v5(namespace, data)` _string_
  Generates a UUID version 5, based on the provided namespace using SHA1

#### [Parameters](/content/docs/apis/actions/modules#parameters/index.html)

- `namespace` _UUID_/ _string_
  Namespace to be used in the hashing function. Either provide one of defined [namespaces](/content/docs/apis/actions/modules#namespaces/index.html) or a string representing a UUID.
- `data` _[]byte_/ _string_
  data to be used in the hashing function. Possible types are []byte or string.

### [Namespaces](/content/docs/apis/actions/modules#namespaces/index.html)

The following predefined namespaces can be used for `uuid.v3` and `uuid.v5`:

- `uuid.namespaceDNS` _UUID_
  6ba7b810-9dad-11d1-80b4-00c04fd430c8
- `uuid.namespaceURL` _UUID_
  6ba7b811-9dad-11d1-80b4-00c04fd430c8
- `uuid.namespaceOID` _UUID_
  6ba7b812-9dad-11d1-80b4-00c04fd430c8
- `uuid.namespaceX500` _UUID_
  6ba7b814-9dad-11d1-80b4-00c04fd430c8

### [Example](/content/docs/apis/actions/modules#example/index.html)

```javascript
let uuid = require("zitadel/uuid")
function setUUID(ctx, api) {
  if (api.metadata === undefined) {
    return;
  }

api.v1.user.appendMetadata('custom-id', uuid.v4());
}
```
