{"id":16482921,"url":"https://github.com/ecthiender/baas-sdk-java","last_synced_at":"2025-09-06T18:39:05.328Z","repository":{"id":140125270,"uuid":"54380740","full_name":"ecthiender/baas-sdk-java","owner":"ecthiender","description":"Java and Android SDK for using the BaaS features of Hasura platform","archived":false,"fork":false,"pushed_at":"2016-07-29T12:20:44.000Z","size":317,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T22:41:52.885Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ecthiender.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-21T10:43:10.000Z","updated_at":"2020-04-06T10:49:38.000Z","dependencies_parsed_at":"2024-03-31T00:15:53.234Z","dependency_job_id":null,"html_url":"https://github.com/ecthiender/baas-sdk-java","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ecthiender/baas-sdk-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecthiender%2Fbaas-sdk-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecthiender%2Fbaas-sdk-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecthiender%2Fbaas-sdk-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecthiender%2Fbaas-sdk-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecthiender","download_url":"https://codeload.github.com/ecthiender/baas-sdk-java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecthiender%2Fbaas-sdk-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273947397,"owners_count":25196388,"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","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-11T13:12:28.313Z","updated_at":"2025-09-06T18:39:05.285Z","avatar_url":"https://github.com/ecthiender.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"This Android SDK is for hauthy and hasuradb APIs.\n\n#Structure\n\nThis SDK is composed of 2 parts.\nThe first part, like a normal SDK, provides an API to login, register, logout and make hasuradb queries.\nThe second part auto-generates relevant classes as a part of your app code so that you can use your hasuradb\ntables as native Java objects. A gradle task needs to be run to auto-generate this code.\n\n\n#Usage\n##Step 0: Pre-requisites\nPlease make sure that your Gradle is \u003e= 2.12\n\n##Step 1: Include dependencies\nThis SDK is available via jitpack.\nAdd the following code to your build.gradle (at a module level, not necessarily the build.gradle of the entire project).\n\n``build.gradle``\n```\ndependencies {\n   compile 'com.github.hasura:baas-sdk-java:617ac3b58c'\n}\n...\n\nbuildscript {\n   repositories {\n      jcenter()\n         maven { url \"https://jitpack.io\" }\n   }\n   dependencies {\n      classpath 'com.github.hasura.baas-sdk-java:hasura-db-codegen:617ac3b58c'\n   }\n}\n\ntask generate \u003c\u003c {\n\n   // Read admin credentials\n   Properties props = new Properties()\n   props.load(new FileInputStream(\"hasura.properties\"))\n\n   // Build Generation Configuration\n   // ------------------------------\n   def cfg = new io.hasura.db.util.Configuration();\n   cfg.setDir(props.getProperty(\"dir\"))\n   cfg.setPackageName(props.getProperty(\"package\"))\n   cfg.setDBUrl(props.getProperty(\"url\"))\n   cfg.setDBPrefix(props.getProperty(\"dbprefix\"))\n   cfg.setAdminAPIKey(props.getProperty(\"adminAPIKey\"))\n\n   // Run the code generator\n   // ----------------------\n   io.hasura.db.util.GenerationUtil.generate(cfg)\n}\n```\n\n##Step 2: Add Hausra admin credentials\nNext to the ``build.gradle`` file where the configuration mentioned above was added,\ncreate a new file called ``hasura.properties``.\nThe gradle task created above, will use configuration values from this file to\nautomatically create classes in your application module. Let's say that our\napp module is ``com.myapp`` then the following values in hasura.properties will\nbe appropriate.\n\n``hasura.properties``\n```\nurl=http://\u003cYOUR-HASURA-PROJECT-IP\u003e/data\nadminAPIKey=\u003cYOUR-VALID-HASURA-ADMIN-TOKEN\u003e\npackage=com.myapp.db\ndbprefix=\ndir=src/main/java/com/myapp/db\n```\n\n##Step 3: Add a Hasura singleton class to intialize the DB and Auth components\nThe Hasura singleton class is just a convenient wrapper. You can use it as\nper your own style. Using the file below as a base is recommended.\n\nLet's say our app module is ``com.myapp``, and our Hasura project name is ``myproject`` then we can add a Hasura singleton\nclass as follows:\n\n``Hasura.java``\n```\npackage com.myapp;\n\nimport android.util.Log;\n\nimport io.hasura.auth.AuthService;\nimport io.hasura.db.DBService;\nimport okhttp3.OkHttpClient;\nimport okhttp3.logging.HttpLoggingInterceptor;\n\npublic class Hasura {\n\n    public static AuthService auth;\n    public static DBService db;\n    private Integer userId;\n    private String sessionId;\n    private String role;\n\n    public static Hasura getInstance() {\n        return currentCtx;\n    }\n\n    public static void setClient() {\n\n        // Ready\n        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();\n        logging.setLevel(HttpLoggingInterceptor.Level.BODY);\n\n        OkHttpClient c = new OkHttpClient.Builder()\n            .addInterceptor(new HasuraTokenInterceptor())\n            .addInterceptor(logging)\n            .build();\n\n        Hasura.auth = new AuthService(\"http://auth.myproject.hasura-app.io\", c);\n        Hasura.db = new DBService(\"http://data.myproject.hasura-app.io/api/1\", \"\", c);\n    }\n\n    public static Integer getCurrentUserId() {\n        return currentCtx.userId;\n    }\n\n    public static String getCurrentRole() {\n        return currentCtx.role;\n    }\n\n    public static String getCurrentSessionId () {\n        return currentCtx.sessionId;\n    }\n\n    public static void setCurrentSession(Integer userId, String role, String sessionId) {\n        Log.d(\"{{HASURA :: AUTH\", \"Setting current session\");\n\n        if (role == null) {\n            role = \"anonymous\";\n        }\n\n        currentCtx.userId = userId;\n        currentCtx.sessionId = sessionId;\n        currentCtx.role = role;\n\n        // Reset the current client so that we are logged in\n        setClient();\n    }\n\n    private static final Hasura currentCtx = new Hasura();\n\n}\n\n```\n\nThen add one more file as follows to automate the auth token handling:\n``HasuraTokenInterceptor.java``\n```\npackage com.myapp;\n\nimport android.util.Log;\n\nimport java.io.IOException;\n\nimport okhttp3.Interceptor;\nimport okhttp3.Request;\nimport okhttp3.Response;\n\npublic class HasuraTokenInterceptor implements Interceptor {\n    @Override\n    public Response intercept(Chain chain) throws IOException {\n        Request request = chain.request();\n        Response response;\n        Log.d(\"{{HASURA INTERCEPTOR\", request.headers().toString());\n        String session = Hasura.getCurrentSessionId();\n        String role = Hasura.getCurrentRole();\n\n        if (session == null)  {\n            response = chain.proceed(request);\n        } else {\n            Request newRequest = request.newBuilder()\n                    .addHeader(\"Authorization\", \"Hasura \" + session)\n                    .addHeader(\"X-Hasura-Role\", role)\n                    .build();\n            Log.d(\"{{HASURA INTERCEPTOR\", newRequest.headers().toString());\n            response = chain.proceed(newRequest);\n        }\n\n        return response;\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecthiender%2Fbaas-sdk-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecthiender%2Fbaas-sdk-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecthiender%2Fbaas-sdk-java/lists"}