Quickstart: React
#
OverviewThis is a brief example how you can integrate Architect SDK into your existing React application.
#
Install Architect SDKInstall Architect SDK via:
- npm
- Yarn
You should see architect-sdk
dependency added to package.json file1.
#
Setup environmentIn your .env
2 file add this line:
After adding REACT_APP_BASE_URL
enviroment variable, you are ready to proceed with the creation of your Architect Service.
#
Setup Architect clientCreate new file called architectConfig.ts
inside src
folder. In order to take full advantage of our type system you should define resources type and pass them to architectSDK configuration. For example if you are making todo app
, you should define Todo
type and pass it to architectSDK like this:
Your resource type or in this case Todo
type can contain any of the fields you want your resource to contain3. Like the following:
You will now have full autocomplete for todos (and any additional resources you define) in editor of your choice.
#
Setup Architect SDK serviceCreate a new file called architect-sdk.service.ts
and place it in your app folder.
With basic CRUD
operations architect-sdk.service.ts
might look like this:
And ArchitectService can be successfully imported in your React component:
#
ConclusionIntegrating Architect SDK into your application is easy using simple steps provided above. If you want to see how small phonebook application utilises Architect SDK go and check link to tutorial. There you can see how authorization, CRUD operations and file upload can be handled in React applications.
- In order to use yarn you first need to configure CLI to use it. Go to this blog for more details.↩
- To setup your enviroment variables, follow this tutorial↩
- Architect imports
createdAt
,updatedAt
andid
fields automatically into your resource.↩