create-client icon indicating copy to clipboard operation
create-client copied to clipboard

Add Angular generator

Open mysiar opened this issue 7 years ago • 15 comments

Add Angular generator to API-Platform client-generator. With React, Vue.js and shortly coming React Native this could be the most comprehensive front app support for API-Platform

mysiar avatar Sep 28 '17 18:09 mysiar

There is an existing community project: https://github.com/momenttech/lysis, see https://github.com/momenttech/lysis/issues/1.

(ping @momenttech)

dunglas avatar Sep 28 '17 19:09 dunglas

Any news for this ?

sbacem avatar Oct 13 '17 12:10 sbacem

@sbacem you are more than welcome to develop this if you are interested

mysiar avatar Oct 13 '17 21:10 mysiar

I am very interested, but i haven't time to do it 😞 😞

sbacem avatar Oct 17 '17 21:10 sbacem

You can try https://github.com/momenttech/lysis

dunglas avatar Oct 18 '17 07:10 dunglas

Hi all, I'm writing under this issue because I also was looking for an Angular generator.

I've just tried lysis on a project of mine but I got some errors:

Starting API 'http://localhost/api/docs.jsonld'...
Error for API 'http://localhost/api/docs.jsonld'
The class http://www.w3.org/ns/hydra/core#ApiDocumentation doesn't exist.

Did anyone manage to make it work recently?

In any case, I've started to work on a generator for Angular. Is there a minimum set of features that should be present in the generator in order to merge that?

At the moment, I'm generating the following for each resource:

  • Interface class (the same as the typescript generator)
  • Service class: this handles getCollection,addItem,getItem,putItem,deleteItem operations

plus an utils file that handles some common stuff.

I also wanted to handle subresources, but it seems quite complicated to do with the current data that's parsed from the Hydra documentation. Does anyone from the maintainers know of an easy way to handle subresources?

Anyway, this is an example of generated files from a project of mine with the current generator:

Resource Interface:

import { Company } from "./company";

export interface Client {
  '@id'?: string;
  id: string;
  name?: string;
  legalName?: string;
  legalAddressCity?: string;
  legalAddressStreet?: string;
  legalAddressStreetNumber?: string;
  legalAddressZipcode?: string;
  phone?: string;
  email?: string;
  vatNumber?: string;
  taxNumber?: string;
  readonly updatedAt?: Date;
  readonly createdAt?: Date;
  readonly agency?: Company;
  readonly locationsCount?: number;
}

Resource service:

import { Client } from "../interfaces/client";
import { HttpClient } from "@angular/common/http";
import { APIPlatformPagedCollection } from "../utils/utils";
import { Inject, Injectable} from '@angular/core';

@Injectable()
export class ClientService {

  constructor(
    private http: HttpClient,
    @Inject('BASE_API_URL') private baseUrl: string
  ) {
  }

  getCollection(){
    return this.http.get<Client>(`${this.baseUrl}/api/clients`);
  }

  addItem(item: Client){
    return this.http.post<Client>(`${this.baseUrl}/api/clients`, item);
  }

  getItem(id: string){
    return this.http.get<Client>(`${this.baseUrl}/api/clients/${id}`);
  }

  updateItem(item: Client){
    return this.http.put<Client>(`${this.baseUrl}/api/clients/${item.id}`, item);
  }

  deleteItem(id: string){
    return this.http.delete<{}>(`${this.baseUrl}/api/clients/${id}`);
  }
}

Utils file:

export interface APIPlatformPagedCollection<T> {
  "hydra:totalItems"?: number;
  "hydra:member"?: T[];
  "@context"?: string;
  "@id"?: string;
  "@type"?: string;
  "hydra:view"?: {
    "@id"?: string;
    "@type"?: string;
    "hydra:first"?: string;
    "hydra:last"?: string;
    "hydra:previous"?: string;
    "hydra:next"?: string;
  };
}

export interface APIPlatformCollection<T> {
  "hydra:totalItems"?: number;
  "hydra:member"?: T[];
  "@context"?: string;
  "@id"?: string;
  "@type"?: string;
}

luca-nardelli avatar Apr 16 '19 22:04 luca-nardelli

Hi @dunglas, is there the possibility that this angular generator will be developed by core members?

simocheccoli avatar Apr 20 '21 17:04 simocheccoli

@simocheccoli I'm not aware of any core member working on this (nor using Angular actually), but we'll be glad to merge a generator if the community contributes one!

dunglas avatar Apr 20 '21 20:04 dunglas

@dunglas we can try it! maybe with @luca-nardelli helps

simocheccoli avatar Apr 21 '21 09:04 simocheccoli

@dunglas we are creating a dummy angular generator with @luca-nardelli 😄 We also want generate a simple material design template angular generator, maybe next week we can sumbit a pr

simocheccoli avatar May 07 '21 08:05 simocheccoli

Hello. Are there any updates on this?

krstns avatar Apr 07 '22 06:04 krstns

No, but a contribution is still very welcome.

dunglas avatar Apr 08 '22 19:04 dunglas

@dunglas @krstns we are still working about it

simocheccoli avatar Aug 09 '22 16:08 simocheccoli

@simocheccoli any updates? I'd like to contribute to the project if needed.

jalexmelendez avatar Jun 08 '23 04:06 jalexmelendez

A good starting point for making a generator is an example client app that works with Api Platform. One then builds a generator that generates the same app code. I followed this proces with my tutorial and the accompanying extended generators for react and next.js.

I even added working Angular app examples:

But my extended generators did get little stars so i did not bother to make one for Angular. However, if someone would like to sponsor me i would be happy to develop a generator similar the the react or next.js generator.

BTW, Angular also supports PWA, similar to next.js but i did not look into that.

metaclass-nl avatar Jun 08 '23 12:06 metaclass-nl