<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Code September on Medium]]></title>
        <description><![CDATA[Stories by Code September on Medium]]></description>
        <link>https://medium.com/@code.september.dev?source=rss-184b0479d5ba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*N4FN3mxDymd2Un5pWi-Lsg.png</url>
            <title>Stories by Code September on Medium</title>
            <link>https://medium.com/@code.september.dev?source=rss-184b0479d5ba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 03:44:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@code.september.dev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Flutter Mqtt Tutorial]]></title>
            <link>https://medium.com/@code.september.dev/flutter-mqtt-tutorial-d991b12ec54a?source=rss-184b0479d5ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/d991b12ec54a</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter-mqtt]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[mqtt]]></category>
            <category><![CDATA[message-broker]]></category>
            <dc:creator><![CDATA[Code September]]></dc:creator>
            <pubDate>Wed, 23 Oct 2024 07:34:54 GMT</pubDate>
            <atom:updated>2024-10-23T07:44:03.498Z</atom:updated>
            <content:encoded><![CDATA[<p>Okay, let’s get to the point, for a detailed explanation you can visit the <a href="https://mqtt.org/">official mqtt website</a>.</p><p>we add the <a href="https://pub.dev/packages/mqtt_client">mqtt package for flutter</a></p><p>here I will provide a tutorial on using mqtt in flutter. in this case I will use mqtt for my chat project to detect when our chat partner is typing.<br>in this case I will make the mqtt function support mobile and web.</p><p>we create the interface first. we name the file <strong>mqtt_client.dart</strong></p><pre>abstract class MqttService{<br>  Future&lt;void&gt; connectMQTT({<br>    required Function() onConnected,<br>    required Function() onDisconnected,<br>    required Function(String topic) onSubscribed,<br>    required Function(Exception e) onError,<br>  });<br><br>  int publishMessage(<br>      String topic,<br>      MqttQos qualityOfService,<br>      MqttClientPayloadBuilder data,<br>      {bool retain = false});<br><br>  void subscribe(String topic, MqttQos qosLevel, Function(String message) onMessage);<br>  void mqttDisconnect();<br>}</pre><p>now we create the mqtt function for the mobile app part. we name the file <strong>mqtt_service_impl.dart</strong></p><pre>class MqttServiceImpl implements MqttService{<br>  MqttServiceImpl(this.mqttServer, this.mqttServerIdentifier){<br>    client = MqttServerClient(mqttServer, &#39;&#39;);<br>  }<br><br>  final String mqttServer;<br>  final String mqttServerIdentifier;<br><br>  late MqttClient client;<br><br>  @override<br>  Future&lt;void&gt; connectMQTT({<br>    required Function() onConnected,<br>    required Function() onDisconnected,<br>    required Function(String topic) onSubscribed,<br>    required Function(Exception e) onError,<br>  }) async {<br>    client.logging(on: false);<br>    client.setProtocolV311();<br>    client.keepAlivePeriod = 20;<br>    client.connectTimeoutPeriod = 2000;<br>    client.onDisconnected = (){<br>      debugPrint(&#39;Mosquitto OnDisconnected client callback - Client disconnection&#39;);<br>      if (client.connectionStatus!.disconnectionOrigin == MqttDisconnectionOrigin.solicited) {<br>        debugPrint(&#39;Mosquitto OnDisconnected callback is solicited, this is correct&#39;);<br>      } else {<br>        debugPrint(&#39;Mosquitto OnDisconnected callback is unsolicited or none, this is incorrect - exiting&#39;);<br>      }<br>      onDisconnected.call();<br>    };<br>    client.onConnected = () {<br>      onConnected.call();<br>    };<br>    client.onSubscribed = (String topic){<br>      onSubscribed.call(topic);<br>      debugPrint(&#39;Mosquitto client Subscribed to Topic $topic&#39;);<br>    };<br>    final connMess = MqttConnectMessage()<br>        .withClientIdentifier(mqttServerIdentifier)<br>        .withWillTopic(&#39;willtopic&#39;)<br>        .withWillMessage(&#39;My Will message&#39;)<br>        .startClean()<br>        .withWillQos(MqttQos.atLeastOnce);<br>    client.connectionMessage = connMess;<br><br>    try {<br>      await client.connect();<br>    } on NoConnectionException catch (e) {<br>      client.disconnect();<br>      debugPrint(&#39;Mosquitto client exception - $e&#39;);<br>      onError.call(e);<br>    }<br>  }<br><br>  @override<br>  int publishMessage(topic, qualityOfService, data, {bool retain = false}) {<br>    return client.publishMessage(topic, qualityOfService, data.payload!);<br>  }<br><br>  @override<br>  void subscribe(String topic, MqttQos qosLevel, Function(String message) onMessage) {<br>    client.subscribe(topic, qosLevel);<br>    client.updates?.listen((List&lt;MqttReceivedMessage&lt;MqttMessage?&gt;&gt;? c) {<br>      final recMess = c![0].payload as MqttPublishMessage;<br>      final pt = MqttPublishPayload.bytesToStringAsString(recMess.payload.message);<br>      onMessage.call(pt);<br>      debugPrint(&#39;Mosquitto Change notification:: topic is ${c[0].topic}, payload is $pt&#39;);<br>    });<br><br><br>    client.published?.listen((MqttPublishMessage message) {<br>      debugPrint(<br>          &#39;Mosquitto Published message topic is &#39;<br>              &#39;${message.variableHeader!.topicName}, &#39;<br>              &#39;with Qos ${message.header!.qos}&#39;);<br>    });<br>  }<br><br>  @override<br>  void mqttDisconnect() {<br>    client.disconnect();<br>  }<br>}</pre><p>now for web support <strong>mqtt_web_service_impl.dart</strong></p><pre>class MqttServiceImpl implements MqttService{<br>  MqttServiceImpl(this.mqttServer, this.mqttServerIdentifier){<br>    mqttServer = &#39;ws://$mqttServer&#39;;<br>    client = MqttBrowserClient(mqttServer, mqttServerIdentifier);<br>  }<br><br>  late String mqttServer;<br>  final String mqttServerIdentifier;<br><br>  late MqttClient client;<br><br>  @override<br>  Future&lt;void&gt; connectMQTT({<br>    required Function() onConnected,<br>    required Function() onDisconnected,<br>    required Function(String topic) onSubscribed,<br>    required Function(Exception e) onError,<br>  }) async {<br>    client.logging(on: false);<br>    client.setProtocolV311();<br>    client.keepAlivePeriod = 20;<br>    client.connectTimeoutPeriod = 2000;<br>    client.port = 8080;<br>    client.websocketProtocols = MqttClientConstants.protocolsSingleDefault;<br>    client.onDisconnected = (){<br>      debugPrint(&#39;Mosquitto OnDisconnected client callback - Client disconnection&#39;);<br>      if (client.connectionStatus!.disconnectionOrigin == MqttDisconnectionOrigin.solicited) {<br>        debugPrint(&#39;Mosquitto OnDisconnected callback is solicited, this is correct&#39;);<br>      } else {<br>        debugPrint(&#39;Mosquitto OnDisconnected callback is unsolicited or none, this is incorrect - exiting&#39;);<br>      }<br>      onDisconnected.call();<br>    };<br>    client.onConnected = () {<br>      onConnected.call();<br>    };<br>    client.onSubscribed = (String topic){<br>      onSubscribed.call(topic);<br>      debugPrint(&#39;Mosquitto client Subscribed to Topic $topic&#39;);<br>    };<br>    final connMess = MqttConnectMessage()<br>        .withClientIdentifier(mqttServerIdentifier)<br>        .withWillTopic(&#39;willTopic&#39;)<br>        .withWillMessage(&#39;My Will message&#39;)<br>        .startClean()<br>        .withWillQos(MqttQos.atLeastOnce);<br>    client.connectionMessage = connMess;<br><br>    try {<br>      await client.connect();<br>    } on NoConnectionException catch (e) {<br>      client.disconnect();<br>      debugPrint(&#39;Mosquitto client exception - $e&#39;);<br>      onError.call(e);<br>    }<br>  }<br><br>  @override<br>  int publishMessage(topic, qualityOfService, data, {bool retain = false}) {<br>    return client.publishMessage(topic, qualityOfService, data.payload!);<br>  }<br><br>  @override<br>  void subscribe(String topic, MqttQos qosLevel, Function(String message) onMessage) {<br>    client.subscribe(topic, qosLevel);<br>    client.updates?.listen((List&lt;MqttReceivedMessage&lt;MqttMessage?&gt;&gt;? c) {<br>      final recMess = c![0].payload as MqttPublishMessage;<br>      final pt = MqttPublishPayload.bytesToStringAsString(recMess.payload.message);<br>      onMessage.call(pt);<br>      debugPrint(&#39;Mosquitto Change notification:: topic is ${c[0].topic}, payload is $pt&#39;);<br>    });<br><br><br>    client.published?.listen((MqttPublishMessage message) {<br>      debugPrint(<br>          &#39;Mosquitto Published message topic is &#39;<br>              &#39;${message.variableHeader!.topicName}, &#39;<br>              &#39;with Qos ${message.header!.qos}&#39;);<br>    });<br>  }<br><br>  @override<br>  void mqttDisconnect() {<br>    client.disconnect();<br>  }<br>}</pre><pre>const String mqttServer = &#39;test.mosquitto.org&#39;;</pre><p>so that we can use both mqtt mobile and web functions, here is the key</p><pre>import &#39;package:mqtt_service_impl.dart&#39;<br>if (dart.library.js) &#39;package:mqtt_web_service_impl.dart&#39;;<br><br><br>class TypingService{<br>  final mqttService = MqttServiceImpl(mqttServer, mqttServerIdentifier);<br><br>  Future&lt;void&gt; connectMQTT() async {<br>    await mqttService.connectMQTT(<br>      onConnected: () {<br>        print(&#39;onConnected&#39;);<br>      },<br>      onDisconnected: () {<br>        print(&#39;onDisconnected&#39;);<br>      },<br>      onError: (e) {<br>        print(&#39;onError ${e.toString()}&#39;);<br>      },<br>      onSubscribed: (topic) {<br>        print(&#39;onSubscribed ${topic}&#39;);<br>      },<br>    );<br>  }<br><br>  Future&lt;void&gt; publishMessage({required String message}) async {<br>      final builder = MqttClientPayloadBuilder();<br>      builder.addString(message);<br>      mqttService.publishMessage(<br>          &#39;topic&#39;,<br>          MqttQos.exactlyOnce, builder<br>      );<br>    }<br><br>  @override<br>  Future&lt;void&gt; subscribe() async {<br>    mqttService.subscribe(<br>      &#39;topic&#39;<br>      MqttQos.atMostOnce,<br>      (message) {<br>        print(message);<br>      },<br>    );<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d991b12ec54a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Http Interceptor]]></title>
            <link>https://medium.com/@code.september.dev/http-client-interceptor-071b08f268ab?source=rss-184b0479d5ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/071b08f268ab</guid>
            <category><![CDATA[requests-library]]></category>
            <category><![CDATA[interceptors]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[http-client]]></category>
            <category><![CDATA[http-interceptors]]></category>
            <dc:creator><![CDATA[Code September]]></dc:creator>
            <pubDate>Tue, 22 Oct 2024 15:21:48 GMT</pubDate>
            <atom:updated>2024-10-22T15:33:03.003Z</atom:updated>
            <content:encoded><![CDATA[<p>The interceptor is the portal when making a request to the server using the http protocol.<br>When we work client side we always deal with interceptors. As a software developer we know what interceptors are, but most people can’t use them properly.</p><p>Interceptors are middleware that allows common patterns around retrying, caching, logging, and authentication to be abstracted away from individual requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rdOaAwjmJ34jM838Sl_W_A.png" /><figcaption>Interceptor Diagram</figcaption></figure><p>This interceptor is usually a derivative function of the http client library that we use. for example if we work as an Android Developer http client library commonly used is <a href="https://square.github.io/okhttp/">Okhttp</a>, in IOS there is <a href="https://github.com/Alamofire/Alamofire">Alamofire</a>, in node.js there is <a href="https://axios-http.com/">axios</a>, in flutter there is <a href="https://pub.dev/packages/dio">Dio</a>, and other http client libraries.</p><p>You can use interceptors to implement a variety of common patterns, such as:</p><ul><li>Adding authentication headers to outgoing requests to a particular API.</li><li>Retrying failed requests with exponential backoff.</li><li>Caching responses for a period of time, or until invalidated by mutations.</li><li>Customizing the parsing of responses.</li><li>Measuring server response times and log them.</li><li>Driving UI elements such as a loading spinner while network operations are in progress.</li><li>Collecting and batch requests made within a certain timeframe.</li><li>Automatically failing requests after a configurable deadline or timeout.</li><li>Regularly polling the server and refreshing results.</li></ul><p>Example:</p><p>Flutter Dio</p><pre>class MapGoogleNetworkInterceptor extends Interceptor {<br>  MapGoogleNetworkInterceptor({<br>    required this.sessiontoken,<br>    required this.key,<br>    this.iosBundleId,<br>    this.androidPackage,<br>    this.androidCert,<br>  });<br>  final String sessiontoken;<br>  final String key;<br>  final String? iosBundleId;<br>  final String? androidPackage;<br>  final String? androidCert;<br><br>  @override<br>  void onRequest(<br>      RequestOptions options, RequestInterceptorHandler handler) async {<br>    options.queryParameters[&quot;sessiontoken&quot;] = sessiontoken;<br>    options.queryParameters[&quot;key&quot;] = key;<br>    if (Platform.isAndroid) {<br>      options.headers[&quot;X-Android-Package&quot;] = androidPackage;<br>      options.headers[&quot;X-Android-Cert&quot;] = androidCert;<br>    } else if (Platform.isIOS) {<br>      options.headers[&quot;X-Ios-Bundle-Identifier&quot;] = iosBundleId;<br>    }<br><br>    return handler.next(options);<br>  }<br><br>  @override<br>  void onError(DioException err, ErrorInterceptorHandler handler) {<br>    return handler.next(err);<br>  }<br><br>  @override<br>  void onResponse(Response response, ResponseInterceptorHandler handler) async {<br>    return handler.next(response);<br>  }<br>}<br></pre><p>Kotlin Okhttp</p><pre>class NetworkInterceptor(private val pref: Preference) : Interceptor {<br><br>    private val urlsExceptionAuthorization = arrayOf(LOGIN, LOGIN_SOCMED, REGISTER)<br><br>    @Throws(IOException::class)<br>    override fun intercept(chain: Interceptor.Chain): Response {<br>        val originRequest = chain.request()<br>        val requestWithUserAgent = originRequest.newBuilder().apply {<br>            val endPoint = getEndPoint(originRequest.url.toString())<br>            if (endPoint !in urlsExceptionAuthorization) {<br>                header(&quot;Authorization&quot;, token)<br>                val refTypeAvailable = originRequest.header(&quot;ref-type&quot;)<br>                header(&quot;ref-type&quot;, refTypeAvailable ?: refType)<br>            }<br><br>            if (originRequest.method == &quot;GET&quot;) {<br>                header(&quot;Content-Type&quot;, &quot;application/json&quot;)<br>                header(&quot;Accept&quot;, &quot;application/json&quot;)<br>            }<br>            header(&quot;is-mobile&quot;, &quot;true&quot;)<br>            header(&quot;Device-Os&quot;, &quot;Android&quot;)<br>            header(&quot;Os-Type&quot;, versionOS())<br>            header(&quot;device-brand&quot;, Build.BRAND)<br>            header(&quot;device-model&quot;, Build.MODEL)<br>            header(&quot;App-Version&quot;, BuildConfig.VERSION_NAME)<br>            header(&quot;Build-Number&quot;, BuildConfig.VERSION_CODE.toString())<br><br>        }.build()<br>        return chain.proceed(requestWithUserAgent)<br>    }<br><br>    private fun getEndPoint(url: String?): String {<br>        val uri = Uri.parse(url)<br>        return uri.path.toString().replace(API_VERSION, &quot;&quot;)<br>    }<br><br>    private fun getSession(): SignIn {<br>        val data: String? = pref.getString(Constants.SESSION)<br>        return if (data != null) {<br>            SystemUtil.gsonBuilder().fromJson(data, SignIn::class.java)<br>        } else {<br>            SignIn()<br>        }<br><br>    }<br><br>    private val token get() = Constants.BEARER.format(getSession().token)<br>    private val refType get() = getSession().refType.orEmpty()<br><br>    private fun versionOS(): String {<br>        return when (val level = Build.VERSION.SDK_INT) {<br>            16 -&gt; &quot;Jelly Bean&quot;<br>            17 -&gt; &quot;Jelly Bean MR1&quot;<br>            18 -&gt; &quot;Jelly Bean MR2&quot;<br>            19 -&gt; &quot;Kitkat&quot;<br>            20 -&gt; &quot;Kitkat Watch&quot;<br>            else -&gt; return &quot;Android API Level: $level&quot;<br>        }<br>    }<br>}</pre><p>Swift Alamofire</p><pre>public class MyInterceptor: RequestInterceptor{<br>    <br>    let userDefault: UserDefaultService<br>    <br>    private let urlsRequiringToken: Set&lt;String&gt; = [<br>        MyApiStatic.signInPath<br>    ]<br>    <br>    public init(userDefault: UserDefaultService) {<br>        self.userDefault = userDefault<br>    }<br>    <br>    public func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result&lt;URLRequest, Error&gt;) -&gt; Void) {<br>        var modifiedRequest = urlRequest<br>        if(needsToken(for: urlRequest.url)){<br>            if let signIn = userDefault.getSession() {<br>                if let token = signIn.token {<br>                    modifiedRequest.addValue(&quot;Bearer \(token)&quot;, forHTTPHeaderField: &quot;Authorization&quot;)<br>                }<br>            }<br>        }<br>        modifiedRequest.addValue(&quot;application/json&quot;, forHTTPHeaderField: &quot;Accept&quot;)<br>        modifiedRequest.addValue(&quot;application/json&quot;, forHTTPHeaderField: &quot;Content-Type&quot;)<br>        completion(.success(modifiedRequest))<br>    }<br>        <br>    public func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -&gt; Void) {<br>        completion(.doNotRetry)<br>    }<br>    <br>    private func needsToken(for url: URL?) -&gt; Bool {<br>        guard let url = url else { return false }<br>        return urlsRequiringToken.contains(url.path)<br>    }<br>}</pre><p>With this Interceptor, the benefit I feel when using interceptors is that it reduces the writing of repeated parameters in each request, if there is an addition to the global request parameter, I only need to change it in one class.</p><p>References<br><a href="https://angular.dev/guide/http/interceptors">https://angular.dev/guide/http/interceptors</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=071b08f268ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self Hosted Firebase Database Alternative and Open Souce is Parse Platform]]></title>
            <link>https://medium.com/@code.september.dev/self-hosted-firebase-database-alternative-and-open-souce-is-parse-platform-50b3e1c3b582?source=rss-184b0479d5ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/50b3e1c3b582</guid>
            <category><![CDATA[chat]]></category>
            <category><![CDATA[parse-server]]></category>
            <category><![CDATA[firebase-alternative]]></category>
            <category><![CDATA[realtime-database]]></category>
            <category><![CDATA[parse-platform]]></category>
            <dc:creator><![CDATA[Code September]]></dc:creator>
            <pubDate>Mon, 21 Oct 2024 15:12:38 GMT</pubDate>
            <atom:updated>2024-10-22T08:21:33.769Z</atom:updated>
            <content:encoded><![CDATA[<p>Based on my experience in both web and mobile development, the features of the firebase database are very good, especially if we are mobile or front end developers who do not need beckend code at all to build an application.</p><p>But over time, there are many specialized applications that are not suitable if we still use the firebase database..</p><p>Let’s get to the main point.</p><p><strong>Some disadvantages of Firebase Database</strong></p><ol><li><strong>It is difficult to query complex conditions</strong></li><li><strong>Database dashboard makes it difficult to view data</strong></li><li><strong>Restricted to Google Cloud (in this case you cannot use in other cloud services such as AWS, Digitial Ocean and others)</strong></li></ol><p>after looking for several references, I finally found <a href="https://parseplatform.org/">Parse Platform/Parse Server</a></p><p>Parse Server is an open source backend that can be deployed to any infrastructure that can run Node.js. Parse Server works with the Express web application framework. It can be added to existing web applications, or run by itself.</p><p>for technical details you can visit the <a href="https://docs.parseplatform.org/parse-server/guide/">Parse Platform Guide</a>.</p><p><strong>The key points are</strong></p><ol><li><strong>Because it is open source and has a large community, there is a lot of support for various SDK platforms</strong></li><li><strong>Storing data in Parse is built around the Parse Object.</strong></li><li><strong>Using Parse’s Query Builder for data retrieval</strong></li><li><strong>You can use the Live Query feature to replace realtime from the database api even with complicated query conditions</strong></li><li><strong>You can use cloud functions similar to firebase</strong></li></ol><p>Maybe my article is incomplete but my focus here is only on the core. as time goes by I will update.</p><p>for the next maybe we just go straight to the Parse Server code using TypeScript from the scratch.</p><p>I already use parse in my project, for chat or something that requires a realtime database.<br>here is the video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fq4rXJgq5yPU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fshorts%2Fq4rXJgq5yPU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fq4rXJgq5yPU%2Fhq2.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3cd69cd762aa9cb31d14a4e4a0bc7de/href">https://medium.com/media/c3cd69cd762aa9cb31d14a4e4a0bc7de/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50b3e1c3b582" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>