# Code

Replace a function's or library module's code with the REST API. Every change creates a new draft version.

Functions and their settings have their own page: [Functions](/api/rest-functions). This page covers the code itself.

## Replace code

```http
PUT /api/projects/:id/code/:target
```

Body: `{ "code": "..." }`. `target` is a function id (including `before` and `after`) or `lib:<module name>`.

## Library modules and packages

See [Library](/api/rest-library) and [Packages](/api/rest-packages).

Scope for all of these: `functions:write`.
