PWA and http request

Hi

I’m a newbie to PWA and wanted to make a simple login page.
I created a simple page with email and password inputs and a login button.
Now I want the button to call my backend login API (webservice).

I tried creating a service where the code should go but I got a message:
[ERROR] Sorry! ionic g can only be run in an Ionic project directory.

I looked for some info about it but got lost in the way. Where can I have an article or any other helpful information about adding http requests to a PWA project?

Thanks

There’s no requirement to use Ionic’s generators for anything. I don’t. You can write services just like they are described in Angular’s Tour of Heroes.

I tried:
ng generate service login
The generate command requires to be run in an Angular project, but a project definition could not be found.

Same comment about Angular’s generators; you don’t have to use them (and I don’t). Might it make more sense if that error message said “cd inside your project directory; you’re currently outside it”?

Ionic g only works in a folder containing an Ionic app - it has to be the top level folder of your app, not a subfolder.

Ditto with ng g - it only works in an Angular app folder.

Isn’t PWA an ionic/angular project?

I guess it’s not, so how can I create a HTTP client service file for PWA project?

If you don’t get any better answers, mine is “create a new file and write it from scratch”. It’s not very much typing, and will get your eyes, mind, and fingers accustomed to what things should look like, which will help you spot anomalies quicker.

No, a PWA can be created with any js tool…Ionic, Angular, Stencil or plain js.

If you are creating your app with Ionic, Angular or Stencil and you want to use their shortcuts, then you need to stick with their conventions for generating services etc and use “ionic g” or “ng g” etc as appropriate.

Or, as @rapropos suggests, just create the required file and use the appropriate js code, you don’t need any other tools.

I suggest you do a course on PWA, there are several introductory videos on youtube…

https://www.youtube.com/results?search_query=PWA

…and some more, or less detailed courses at Udemy…