Import { CubaApp, FetchOptions } from "@cuba-platform/rest";

Hi there…would like to know how can i use this in angular full steps…trying to connect to CUBA Rest API from angular… i have run the command below from this link CUBA Platform: TypeScript SDK and REST API – Jmix

To generate the SDK, you just need to run

npm install -g @cuba-platform/front-generator
gen-cuba-front sdk:all

my queston is there any link of tutoria on how to set up angular connect to CUBA Rest API using this typescriptSDK (the link i share) . a simple full project and running will do

Regards

Hi @suriaeagle,

You’ll need @cuba-platform/rest library to work with REST API. Check this page for documentation on both the library and REST API itself. This will allow you to authenticate, create and modify entities, etc., see documentation for more details on available endpoints.

TypeScript SDK is the TypeScript representation of your CUBA application’s entities, services, etc. Here is a short introduction. We plan to improve the documentation to describe in more details how to use the SDK, particularly when using a framework other that React. In a nutshell, it allows you to use your CUBA types at frontend side (see entities and enums folders in generated SDK), execute predefined queries by importing restQueries object from queries.ts and invoke service methods by importing restServices object from services.ts.

Hi, you just need couple of steps to setup:

  1. npm install --save @cuba-platform/rest
  2. gen-cuba-front sdk:all then copy generated folder to somewhere in your project, e.g. shared folder, then you can use CubaApp to talk with your backend as described here.

Thanks @v.pushkin and @hanbing.yin for the support… i have checked the linked documentation the instructions and understand the usage of this gen-cuba-front sdk:all

and once i run the angular app i got this error

image

my CUBA App has already set this cuba.rest.allowedOrigins = “*” in web-app.properties

what could be wrong then ? which and where in need to allowed this CORS policy enabled…

regards
SuriaEagle

Hi, all CORS requests to the REST API are allowed by default, you don’t have to set this app property. Could you remove the setting of cuba.rest.allowedOrigins and try again?

Thanks again @hanbing.yin… it finally worked … what i did was

  1. in my business logic service bean i commented out

import org.springframework.web.bind.annotation.CrossOrigin;
//@CrossOrigin(origins = “", allowedHeaders = "”)

  1. and web.app.properties as well
    #cuba.rest.allowedOrigins = “*”

  2. and also i ran again this command again

  1. npm install --save @cuba-platform/rest
  2. gen-cuba-front sdk:all

Finally it worked …thanks