{"id":21455481,"url":"https://github.com/zeppaman/api-farm","last_synced_at":"2025-07-14T23:32:43.208Z","repository":{"id":53755919,"uuid":"345050568","full_name":"zeppaman/api-farm","owner":"zeppaman","description":"A PHP Symfony based extensible low-code platform","archived":false,"fork":false,"pushed_at":"2021-03-18T17:50:17.000Z","size":775,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-18T04:42:27.925Z","etag":null,"topics":["api-platform","graphql","mongodb","php","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zeppaman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-06T09:06:04.000Z","updated_at":"2024-01-10T09:26:07.000Z","dependencies_parsed_at":"2022-09-03T00:11:20.213Z","dependency_job_id":null,"html_url":"https://github.com/zeppaman/api-farm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeppaman%2Fapi-farm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeppaman%2Fapi-farm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeppaman%2Fapi-farm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeppaman%2Fapi-farm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeppaman","download_url":"https://codeload.github.com/zeppaman/api-farm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226002997,"owners_count":17558157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-platform","graphql","mongodb","php","symfony"],"created_at":"2024-11-23T05:12:20.226Z","updated_at":"2024-11-23T05:12:20.780Z","avatar_url":"https://github.com/zeppaman.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API FARM\nApi Farm is a low code platform based on Symfony and MongoDB. It support out of the box:\n\n- Data management\n- Rest API\n- User management\n- Oaut2 authentication (as standalone server, or JWT resource server)\n- OpenID connect support\n- Command line automation\n- GrapQL with query and mutations\n- Dynamic endpoint generation \n\n# Install options \nThe recommended deployments is to use the skeleton project, by the way you can add this bundle to your app or run this bundle directly.\n\n## Using the skeleton\n\n```bash\n# create a project\nCOMPOSER_MEMORY_LIMIT=-1 composer create-project zeppaman/api-farm my-project\n\ncd my-project\n\ndocker-compose up \n\n# configure the application\ndocker-compose exec app ./vendor/bin/apifarm-install apifarm:config [--db-host DB-HOST] [--db-port DB-PORT] [--db-password DB-PASSWORD] [--db-user DB-USER]\n\n# install the database\ndocker-compose exec app  bin/console apifarm:install [--adminuser ADMINUSER] [--adminpassword ADMINPASSWORD] [--db-host DB-HOST] [--db-port DB-PORT] [--db-password DB-PASSWORD] [--db-user DB-USER]\n\n```\n\n# Manual install\n\n```bash\ncomposer require zeppaman/api-farm\n```\n\n1. Enable the core bundles in  bundles.php \n\n    ```bash\n    ApiFarm\\CoreBundle\\CoreBundle::class =\u003e ['all' =\u003e true],\n    ApiFarm\\UiBundle\\UiBundle::class =\u003e ['all' =\u003e true],\n\n    ```\n2. Configure the yaml files by running \n\n    ```bash\n    ./vendor/bin/apifarm-install apifarm:config [--db-host DB-HOST] [--db-port DB-PORT] [--db-password DB-PASSWORD] [--db-user DB-USER]\n    ```\n    This command will create api-farm settings files and will replace the  generated files from `lexik_jwt_authentication` `trikoder_oauth2`. The file, if present are renamed `.old` so that you could merge them manually.\n    The command creates the connection string. Now ApiFarm is ready to go!\n3.  Run `bin/console asset:install --symlink --relative public` for installing assets\n4.  Run the installation process\n    ```bash\n     bin/console apifarm:install [--adminuser ADMINUSER] [--adminpassword ADMINPASSWORD] \n    ```\n    This command will:\n    - create an admin username\n    - generate a key pair used for JWT\n    - create the config.json file that contains the ui module registrations\n    - populate data with a sample collection schema\n5. Configure the server for serving the app. The `/bundles/core/` routes have to be served from  `/bundles/core/index.html`. The following .htaccess have to be placed into your `public` folder (if you use apache!)\n\n    ```bash\n    RewriteEngine on\n\n    RewriteCond %{REQUEST_FILENAME} !-f\n    RewriteCond %{REQUEST_FILENAME} !-d\n    RewriteRule ^bundles/core/(.*)$ /bundles/core/index.html [NC,L,QSA]\n    ```\n\n\n## Run this bundle.\nThis bundle is standalone for development and testing purpose. \n\nJust clone and run it\n```bash\n\ngit clone https://github.com/zeppaman/API-Farm.git .\ndocker-compose up\n\n```\nThen you can follow the installation steps using   `apifarm-install`\n\n```bash\n# configure the application\ndocker-compose exec app ./bundles/InstallBundle/bin/apifarm-install apifarm:config [--db-host DB-HOST] [--db-port DB-PORT] [--db-password DB-PASSWORD] [--db-user DB-USER]\n\n# install the database\ndocker-compose exec app  bin/console apifarm:install [--adminuser ADMINUSER] [--adminpassword ADMINPASSWORD] [--db-host DB-HOST] [--db-port DB-PORT] [--db-password DB-PASSWORD] [--db-user DB-USER]\n\n```\n\n# API Usage\n\nIn this section we will see how to use API Farm.\n\n## Console commands\n\n```bash\nbin/console app:crud:upsert db collection {\\\"filed\\\":\\\"value\\\"}\nbin/console app:crud:find db collection {\\\"filed\\\":\\\"value\\\"}\nbin/console app:crud:delete db collection {\\\"filed\\\":\\\"value\\\"}\n```\n\n\ncurl --location --request POST 'http://localhost/api/data/test/_schemas' \\\n--header 'Content-Type: text/plain' \\\n--data-raw \n\n\n## Api REST \n\nIt uses the resouce URI pattern. \n\n**Collection methods**\n- GET  `http://localhost/api/{db}/{collection}` + GET for list,\n- POST `http://localhost/api/{db}/{collection}`  list,\n\n**item methods**\n- GET `http://localhost/api/{db}/{collection}/{id}`  replace the object,\n- PUT `http://localhost/api/{db}/{collection}/{id}`  replace the object,\n- PATCH `http://localhost/api/{db}/{collection}/{id}`  pathc the object,\n- DELETE `http://localhost/api/{db}/{collection}/{id}`  delete the object,\n\n### find\n\nhttp://localhost/api/data/test/prova?skip=10\u0026limit=20\u0026query={%22title%22:%22value%22}\n\n```\n{\"request\":{\"database\":\"test\",\"collection\":\"test\",\"skip\":\"10\",\"limit\":\"20\",\"query\":\"{}\"},\"data\":[{\"_id\":\"604335dcddfd8c484b4da692\",\"title\":\"mytitle\",\"body\":\"mybody\"},{\"_id\":\"604335ea05dcae70fe1ed752\",\"title\":\"mytitle\",\"body\":\"mybody\"},{\"_id\":\"604335f88288e669541ccb72\",\"title\":\"mytitle\",\"body\":\"mybody\"},{\"_id\":\"6043363cf9265b45a810f262\",\"title\":\"mytitle\",\"body\":\"mybody\"},{\"_id\":\"60433646825e954b41534232\",\"title\":\"mytitle\",\"body\":\"mybody\"},{\"_id\":\"6043368e22619b6cd151d852\",\"title\":\"mytitle\",\"body\":\"mybody\"},{\"_id\":\"6043369ca48c2a285d4682f2\",\"title\":\"mytitle\",\"body\":\"mybody\"},{\"_id\":\"604336f26e205328b82ddd32\",\"title\":\"mytitle\",\"body\":\"mybody\"},{\"_id\":\"6043370630658259257fd982\",\"title\":\"mytitle\",\"body\":\"mybody\"},{\"_id\":\"60433722f915fc6ba00f5292\",\"title\":\"mytitle\",\"body\":\"mybody\"},{\"_id\":\"6043387ef42a7a265a743c02\",\"filed\":\"value\"}],\"metadata\":[]}\n```\n\n### GET\n\nhttp://localhost/api/data/test/test/60428383bdb90439ec593df2\n\n```\n{\"request\":{\"database\":\"test\",\"collection\":\"test\",\"id\":\"60428383bdb90439ec593df2\"},\"data\":{\"_id\":\"60428383bdb90439ec593df2\",\"ddd\":\"ddd\"},\"metadata\":[]}\n```\n\n\n\n# OAUTH2\n\n## Generate a client\n\n```bash\n bin/console trikoder:oauth2:create-client\n\n -------- \n  Identifier                         Secret                                                                                                                            \n ---------------------------------- ---------------------------------------------------------------------------------------------------------------------------------- \n  c0a71bf0379c66c46da3ed41a4f4aab2   e8f9855c30bb9915e61bc093656e75c7e8e3bc3b221eca2be796790af96e6f347b738a28c84ffb9db61617e812b21c51c8b29d9d8d1c92d2df9b386a2404c394  \n ---------------------------------- ---------------------------------------------------------------------------------------------------------------------------------- \n```\n\n## Update a client\n```bash\n\nbin/console trikoder:oauth2:update-client --grant-type client_credentials --grant-type password c0a71bf0379c66c46da3ed41a4f4aab2\n```\n\n## List client\n```bash\nbin/console trikoder:oauth2:list-clients\n```\n\n## Get token\nUsing a token with password protocol:\n\n```bash\ncurl --location --request POST 'localhost/token' \\\n--header 'Content-Type: application/x-www-form-urlencoded' \\\n--data-urlencode 'grant_type=password' \\\n--data-urlencode 'username=bob' \\\n--data-urlencode 'password=xyz' \\\n--data-urlencode 'client_id=c0a71bf0379c66c46da3ed41a4f4aab2' \\\n--data-urlencode 'client_secret=e8f9855c30bb9915e61bc093656e75c7e8e3bc3b221eca2be796790af96e6f347b738a28c84ffb9db61617e812b21c51c8b29d9d8d1c92d2df9b386a2404c394'\n```\n\n## Get User Into\n\nUserinfo is availabel at `localhost/userinfo`.\n\n```bash\ncurl --location --request GET 'localhost/userinfo' --header 'Authorization: Bearer {token}'\n\n\n{\n    \n    \"_id\": \"6043d6703e01b17faf118b53\",\n    \"username\": \"bob\",\n    \"nome\": \"Bobby\" \n     /* any data here*/\n}\n```\n\n# GraphQL\n\nEndpoint is located at `localhost/api/graph/{db}`\n\n```bash\nquery { \n  entity1{\n      _id,\n      title,\n      amount\n  }\n}\n```\n\n```json\n{\n    \"data\": {\n        \"entity1\": [\n            {\n                \"_id\": \"6045038ae0c6cde18c3c93bf\",\n                \"title\": \"test data\",\n                \"amount\": 1000\n            }\n        ]\n    }\n}\n```\n\n\n\n\n\n\n\n# Code lambda\n\nEndpoint is located at `localhost/api/do/{db}/{action}/`\n\n\n```bash\ncurl --location --request GET 'localhost/api/do/{db}/{action}/' \n\n\n\n{\n    \"_id\" : ObjectId(\"60452b54200a9b44267324e8\"),\n    \"name\" : \"test2\",\n    \"code\" : \"return $container['crud']-\u003efind('test','_mutations',[],1,10);\"\n}\n```\n\n\n\n# Setup \u0026 Testing\n\n```bash\n\n#create the client oauht2\ndocker-compose exec app bin/console trikoder:oauth2:create-client --grant-type password c0a71bf0379c66c46da3ed41a4f4aab2\n\ndocker-compose exec app bin/console  app:crud:upsert test \"_users\" '{\"username\":\"admin\",\"newpassword\":\"password\"}'\n#create an entity with fields title and amount\ndocker-compose exec app bin/console  app:crud:upsert test '_schemas' '{ \"name\" : \"entity1\",\"db\" :\"test\",\"fields\":{\"title\":{\"type\": \"text\",            \"name\" : \"title\",\"label\" : \"Title\"},\"amount\" : {\"type\" : \"int\", \"name\" : \"amount\",\"label\" : \"Amount\"}}}'\n\n#get token\ncurl --location --request POST 'localhost/token' \\\n--header 'Content-Type: application/x-www-form-urlencoded' \\\n--data-urlencode 'grant_type=password' \\\n--data-urlencode 'username=admin' \\\n--data-urlencode 'password=password' \\\n--data-urlencode 'client_id={replace}' \\\n--data-urlencode 'client_secret={replace}'\n\n# enter data\ndocker-compose exec app bin/console  app:crud:upsert test \"entity1\" '{\"title\":\"title 1\",\"amount\":100}'\ndocker-compose exec app bin/console  app:crud:upsert test \"entity1\" '{\"title\":\"title 2\",\"amount\":101}'\ndocker-compose exec app bin/console  app:crud:upsert test \"entity1\" '{\"title\":\"title 3\",\"amount\":102}'\ndocker-compose exec app bin/console  app:crud:upsert test \"entity1\" '{\"title\":\"title 4\",\"amount\":103}'\n\n#get data GraphQL\ncurl --location --request GET 'localhost/api/graph/test' --header 'Content-Type: application/json' --data-raw '{\"query\":\"query { \\r\\n  entity1{\\r\\n      _id,\\r\\n      title,\\r\\n      amount\\r\\n  }\\r\\n}\",\"variables\":{}}'\n\ncurl --location --request GET 'http://localhost/api/data/test/entity1' \\\n--header 'Authorization: Bearer {token}'\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeppaman%2Fapi-farm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeppaman%2Fapi-farm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeppaman%2Fapi-farm/lists"}