Skip to content

Commit

Permalink
release: v1.0.0-alpha.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Convly authored Dec 16, 2024
2 parents 5c6f23f + d03f3bc commit f652c9f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,44 +45,52 @@
5. [Examples](#-examples)

## 🛠 Getting started

### Pre-Requisites

Before you begin, ensure you have the following:

- A Strapi backend up and running: [quick start guide](https://docs.strapi.io/dev-docs/quick-start).
- The API URL of your Strapi instance: for example, `http://localhost:1337/api`.
- A recent version of [Node.js](https://nodejs.org/en/download/package-manager) installed.

### Installation

Install the SDK as a dependency in your project:

**NPM**

```bash
npm install @strapi/sdk-js
```

**Yarn**

```bash
yarn add @strapi/sdk-js
```

**pnpm**

```bash
pnpm add @strapi/sdk-js
```

## ⚙️ Creating and configuring the SDK Instance

### Basic configuration

To interact with your Strapi backend, initialize the SDK with your Strapi API base URL:

``` typescript
```typescript
import { createStrapiSDK } from '@strapi/sdk-js';

const sdk = createStrapiSDK({ baseURL: 'http://localhost:1337/api' });
```

Alternatively, use a `<script>` tag in a browser environment:

``` html
```html
<script src="https://cdn.jsdelivr.net/npm/@strapi/sdk-js"></script>

<script>
Expand All @@ -91,13 +99,14 @@ Alternatively, use a `<script>` tag in a browser environment:
```

### Authentication

The SDK supports multiple authentication strategies for accessing authenticated content in your Strapi backend.

#### API-Token authentication

If your Strapi instance uses API tokens, configure the SDK like this:

``` typescript
```typescript
const sdk = createStrapiSDK({
baseURL: 'http://localhost:1337/api',
auth: {
Expand All @@ -110,12 +119,14 @@ const sdk = createStrapiSDK({
## 📚 API Reference

The Strapi SDK instance provides key properties and utility methods for content and API interaction:

- **`baseURL`**: base URL of your Strapi backend.
- **`fetch`**: perform generic requests to the Strapi Content API using fetch-like syntax.
- **`.collection(resource: string)`**: get a manager instance for handling collection-type resources.
- **`.single(resource: string)`**: get a manager instance for handling single-type resources.

## 📁 Resource Managers

### `.collection(resource)`

The `.collection()` method provides a manager for working with collection-type resources,
Expand All @@ -133,7 +144,7 @@ which can have multiple entries.

#### Examples:

``` typescript
```typescript
const articles = sdk.collection('articles');

// Fetch all english articles sorted by title
Expand All @@ -154,6 +165,7 @@ const updatedArticle = await articles.update('article-document-id', { title: 'Up
// Delete an article
await articles.delete('article-id');
```

### `.single(resource)`

The `.single()` method provides a manager for working with collection-type resources, which have only one entry.
Expand All @@ -167,7 +179,8 @@ The `.single()` method provides a manager for working with collection-type resou
3. **`delete(queryParams?)`**: remove the document.

#### Examples:
``` typescript

```typescript
const homepage = sdk.single('homepage');

// Fetch the default version of the homepage
Expand All @@ -177,7 +190,10 @@ const homepageContent = await homepage.find();
const homepageContent = await homepage.find({ locale: 'es' });

// Update the homepage draft content
const updatedHomepage = await homepage.update({ title: 'Updated Homepage Title' }, { status: 'draft' });
const updatedHomepage = await homepage.update(
{ title: 'Updated Homepage Title' },
{ status: 'draft' }
);

// Delete the homepage content
await homepage.delete();
Expand All @@ -187,7 +203,7 @@ await homepage.delete();

Here’s how to combine `.collection()` and `.single()` methods in a real-world scenario:

``` typescript
```typescript
const sdk = createStrapiSDK({
baseURL: 'http://localhost:1337/api',
auth: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@strapi/sdk-js",
"version": "0.0.0",
"version": "1.0.0-alpha.0",
"description": "An SDK you can use the easily interface with Strapi from your javascript project",
"keywords": [
"strapi",
Expand Down

0 comments on commit f652c9f

Please sign in to comment.