The Codex SDK provides an API for interacting with the Codex decentralized storage network.
## Import
```js
import { Codex } from "@codex/sdk-js";
```
or
```js
const { Codex } = require("@codex/sdk-js");
```
## How to use
To create a Codex instance, provide the REST API url to interact with the Codex client:
```js
const codex = new Codex("http://localhost:3000")
```
### Error handling
The SDK provides a type called `SafeValue` for error handling instead of throwing errors. It is inspired by Go's "error as value" concept.
If the value represents an error, `error` is true and `data` will contain the error.
If the value is not an error, `error` is false and `data` will contain the requested data.
The error type is a [CodexError](./src/errors/errors.ts#L15) which can be error object of 3 types:
*`error`: Object containing the error message
*`api`: Object containing the api error message and the status code
*`validation`: Object containing the error message and a field `errors` of type [ValidationError](./src/errors/errors.ts#L3) containing the error message for each fields.