Announcing the Strapi JavaScript SDK ๐
Iโm happy to announce the first public release of the JavaScript SDK for Strapi!
Software Development Kits always make developers life easier to request APIs. Basically, an API SDKs abstracts API calls into functions. This is why most of the API providers (Algolia, Stripe, Twilio, etc.) offer SDKs, ideally in different programming languages.
Since Strapi exposes an API, it also deserves its own SDK.
As an official Strapi contributor for more than six months (take a look at my latest article), I quickly decided to jump on this new SDK development. After some discussions with the core team, I started building it and am proud to announce its first release today. Discover it on GitHub: https://github.com/strapi/strapi-sdk-javascript.
๐ฏ What it does
CRUD
The most basic feature of a Strapi API is to expose a CRUD. That means you can get, create, update and delete entries. Instead of getting, for example, a list of posts using XHR with a request library, simply do the following:
Of course, you can also get, update or delete a single entry. Take a look at the documentation to know more.
Authentication
Your API may be secured, typically thanks to the Users & Permissions plugin, so you require your client to be authenticated before sending requests. Using the SDK, you can easily authenticate users. Then the userโs token will be automatically added to every requests:
Also learn how to register a new user.
Providers Authentication helpers
Strapi does support providers authentication (Facebook, Google, GitHub, etc.).
Files management
As a front-end developer, files management may be complicated. Uploading files requires to convert them to specific formats and so on. Thanks to the SDK, use the upload
function and you will be done:
Last but not least, you can easily retrieve, or even search, one or many files stored in your Strapi API.
๐ Getting started
Want to give it a try? Easy peasy: install it from npm and import it in your project!
Installation
npm install strapi-sdk-javascript
Setup your project
In the example above, we:
- Import the SDK.
- Create a new instance.
- Login a specific user.
- Get the list of posts.
๐๏ธ Resources
Repository
The SDK repository is available on GitHub, under the Strapi organization. Please open an issue if you find any bug or would like some additional features.
Documentation
The documentation is hosted in the same GitHub repository and also available on GitHub pages.
Roadmap
Many features are available in this version, but I am sure you already expect more than that :) Donโt worry, improvements are coming!
GraphQL
As announced in the v3@alpha.12 release, Strapi is now compatible with GraphQL. This has been a huge step for the project! It would be great for the SDK to support it as well.
Attach/Detach entry relationship
In a real world API, an entry is often related to one or many others: a post can be related to an author, a product may be related to a category, etc. Dealing with relation quicly becomes complex with REST. Here is a potential way to manage it using the SDK:
Real Time
Node.js is great for real time! Even if Socket.io can be easily added in Strapi, it is not natively implemented. As soon as it will be available through a plugin, it would be great to update the SDK:
Conclusion
I sincerely hope this SDK will make your life easier!
Please add comments to let me and other community members know what you expect from the SDK.
Thanks!