<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: harrissolangi</title>
    <description>The latest articles on DEV Community by harrissolangi (@harrissolangi).</description>
    <link>https://dev.to/harrissolangi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1005950%2F6c4a0e8b-d8b1-4168-8014-8e22bab6b973.png</url>
      <title>DEV Community: harrissolangi</title>
      <link>https://dev.to/harrissolangi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/harrissolangi"/>
    <language>en</language>
    <item>
      <title>An introduction to Kubernetes, the open-source container orchestration system developed by Google</title>
      <dc:creator>harrissolangi</dc:creator>
      <pubDate>Tue, 17 Jan 2023 13:24:48 +0000</pubDate>
      <link>https://dev.to/harrissolangi/an-introduction-to-kubernetes-the-open-source-container-orchestration-system-developed-by-google-6kc</link>
      <guid>https://dev.to/harrissolangi/an-introduction-to-kubernetes-the-open-source-container-orchestration-system-developed-by-google-6kc</guid>
      <description>&lt;p&gt;Kubernetes is an open-source container orchestration system that was developed by Google. It can be used to manage containerized applications across a cluster of machines. It automates the deployment, scaling, and management of containerized applications.&lt;/p&gt;

&lt;p&gt;To use Kubernetes on Google Cloud, you can use Google Kubernetes Engine (GKE) which allows you to easily create and manage a Kubernetes cluster on Google Cloud.&lt;/p&gt;

&lt;p&gt;An example of how to use Kubernetes to manage a Java application on Google Cloud would be to first package your Java application in a Docker container.&lt;br&gt;
You can use a Dockerfile to create the container image, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM openjdk:8
COPY . /app
WORKDIR /app
RUN javac Main.java
CMD ["java", "Main"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can then create a Kubernetes Deployment to manage the containerized application, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-java-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-java-app
  template:
    metadata:
      labels:
        app: my-java-app
    spec:
      containers:
      - name: my-java-app
        image: gcr.io/my-project/my-java-app:v1
        ports:
        - containerPort: 8080

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and a Service to define how the application can be accessed, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: v1
kind: Service
metadata:
  name: my-java-app
spec:
  selector:
    app: my-java-app
  ports:
  - name: http
    port: 80
    targetPort: 8080
  type: LoadBalancer

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use Kubernetes ConfigMap and Secrets to manage application configuration and secrets separately from your application code, as well as use Kubernetes resource like pod, service and replica set to control how your application is deployed and scaled.&lt;/p&gt;

&lt;p&gt;You can use command-line tools such as 'kubectl' to interact with your Kubernetes cluster and deploy your application.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl apply -f deployment.yml&lt;br&gt;
kubectl apply -f service.yml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Please note that the above code examples are just a simple demonstration of how to use Kubernetes on GCP with a Java application, and a complete implementation will likely require additional configuration and resources.&lt;/p&gt;

</description>
      <category>welcome</category>
    </item>
    <item>
      <title>Creating a basic GET API with Firebase Cloud Functions and Firestore</title>
      <dc:creator>harrissolangi</dc:creator>
      <pubDate>Wed, 11 Jan 2023 09:57:16 +0000</pubDate>
      <link>https://dev.to/harrissolangi/creating-a-basic-get-api-with-firebase-cloud-functions-and-firestore-2ien</link>
      <guid>https://dev.to/harrissolangi/creating-a-basic-get-api-with-firebase-cloud-functions-and-firestore-2ien</guid>
      <description>&lt;p&gt;Creating a GET API that fetches 100 records using Firebase Cloud Functions and Firestore is relatively simple. Here's an example of how to do it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Start by creating a new Firebase Cloud Function and selecting an HTTP trigger.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the function's index.js file, import the Firebase and Firestore modules by adding the following lines at the top:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;const functions = require('firebase-functions');&lt;br&gt;
const admin = require('firebase-admin');&lt;br&gt;
admin.initializeApp();&lt;br&gt;
const db = admin.firestore();&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Then in the function's body you can use the get() method from the firestore collection object with the limit() method that sets the maximum number of documents to retrieve, in this case, you want to get 100 documents.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;exports.get100Records = functions.https.onRequest((req, res) =&amp;gt; {&lt;br&gt;
    db.collection("collection_name")&lt;br&gt;
    .limit(100)&lt;br&gt;
    .get()&lt;br&gt;
    .then(snapshot =&amp;gt; {&lt;br&gt;
        const data = [];&lt;br&gt;
        snapshot.forEach(doc =&amp;gt; {&lt;br&gt;
            data.push(doc.data());&lt;br&gt;
        });&lt;br&gt;
        res.json(data);&lt;br&gt;
    })&lt;br&gt;
    .catch(error =&amp;gt; {&lt;br&gt;
        res.status(500).send(error);&lt;br&gt;
    });&lt;br&gt;
});&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Once your function is ready, you will want to deploy it to Firebase. This can be done by running the following command in your command line: firebase deploy --only functions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now you can test the API endpoint by sending a GET request to the endpoint and checking the results.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note that this is a simplified example.&lt;/p&gt;

&lt;p&gt;Another slightly complex example is shared below : &lt;/p&gt;

&lt;p&gt;`const functions = require('firebase-functions');&lt;br&gt;
const admin = require('firebase-admin');&lt;br&gt;
admin.initializeApp();&lt;br&gt;
const db = admin.firestore();&lt;/p&gt;

&lt;p&gt;exports.get100Records = functions.https.onRequest((req, res) =&amp;gt; {&lt;br&gt;
    // Get request parameters&lt;br&gt;
    const { orderBy, orderDirection, filterBy } = req.query;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Create a reference to the Firestore collection
let collectionRef = db.collection('collection_name');

// Apply sorting if specified
if (orderBy &amp;amp;&amp;amp; orderDirection) {
    collectionRef = collectionRef.orderBy(orderBy, orderDirection);
}

// Apply filtering if specified
if (filterBy) {
    collectionRef = collectionRef.where(filterBy.field, filterBy.op, filterBy.value);
}

// Get the first 100 documents
collectionRef.limit(100).get()
.then(snapshot =&amp;gt; {
    const data = [];
    snapshot.forEach(doc =&amp;gt; {
        data.push(doc.data());
    });
    res.json(data);
})
.catch(error =&amp;gt; {
    console.log(error);
    res.status(500).send(error);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;});&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;In this example, the API endpoint accepts query parameters for sorting (orderBy and orderDirection) and filtering (filterBy) the data before fetching the first 100 records.&lt;/p&gt;

&lt;p&gt;You can test this endpoint by sending a GET request to the endpoint with the appropriate query parameters.&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Create APIs with Firebase</title>
      <dc:creator>harrissolangi</dc:creator>
      <pubDate>Wed, 11 Jan 2023 09:50:20 +0000</pubDate>
      <link>https://dev.to/harrissolangi/create-your-1st-api-with-firebase-3998</link>
      <guid>https://dev.to/harrissolangi/create-your-1st-api-with-firebase-3998</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Go to the Firebase console (&lt;a href="https://console.firebase.google.com/"&gt;https://console.firebase.google.com/&lt;/a&gt;) and create a new project.&lt;/li&gt;
&lt;li&gt;Once you have created your project, navigate to the "Database" section in the left sidebar and click on the "Realtime Database" tab.&lt;/li&gt;
&lt;li&gt;Click on the "Create database" button and choose "Start in test mode" to allow anyone to read and write to your database.&lt;/li&gt;
&lt;li&gt;To connect to the Firebase Realtime Database from your Java application, you will need to install the Firebase SDK using Maven or Gradle, and include it in your code. Here's an example of how to do this in Java:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Import the Firebase SDK
import com.google.firebase.*;
import com.google.firebase.database.*;

// Initialize Firebase
FirebaseOptions options = new FirebaseOptions.Builder()
  .setApiKey("your_api_key")
  .setAuthDomain("your_auth_domain")
  .setDatabaseUrl("your_database_url")
  .setProjectId("your_project_id")
  .setStorageBucket("your_storage_bucket")
  .setMessagingSenderId("your_messaging_sender_id")
  .build();
FirebaseApp.initializeApp(options);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt; Create the API endpoint(s) for your application. For example, here's a simple endpoint for creating a new record in the database:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post("/create", new Route() {
    @Override
    public Object handle(Request request, Response response) {
        // Get the new record from the request body
        Map&amp;lt;String, String&amp;gt; newRecord = new Gson().fromJson(request.body(), Map.class);

        // Get a reference to the database
        DatabaseReference ref = FirebaseDatabase.getInstance().getReference();

        // Push the new record to the database
        ref.push().setValue(newRecord);

        // Send a response
        response.status(200);
        return "Record created successfully.";
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;To deploy your API, you can use a hosting service such as Firebase Hosting or any other service that supports Java.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, you can test your API using a tool such as Postman or curl.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Please note that this is a basic example, it is recommended to also secure your API with Firebase Authentication and Firebase Cloud Firestore Security Rules.&lt;br&gt;
You can find more detailed information and sample code in the Firebase Realtime Database documentation for Java: &lt;a href="https://firebase.google.com/docs/database/admin/start"&gt;https://firebase.google.com/docs/database/admin/start&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, you can use Firebase Admin SDK for Java to interact with Firebase Realtime Database, it has more functionalities like authentication, and security rules checking. &lt;a href="https://firebase.google.com/docs/admin/setup"&gt;https://firebase.google.com/docs/admin/setup&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>googlecloud</category>
      <category>webdev</category>
      <category>java</category>
    </item>
  </channel>
</rss>
