Giter Club home page Giter Club logo

http4s-dom's Introduction

Http4s Build Status Maven Central Typelevel library Cats friendly

Http4s is a minimal, idiomatic Scala interface for HTTP services. Http4s is Scala's answer to Ruby's Rack, Python's WSGI, Haskell's WAI, and Java's Servlets.

val http = HttpRoutes.of {
  case GET -> Root / "hello" =>
    Ok("Hello, better world.")
}

Learn more at http4s.org.

If you run into any difficulties please enable partial unification in your build.sbt (not needed for Scala 2.13 and beyond, because Scala 2.13.0+ has partial unification switched on by default)

scalacOptions ++= Seq("-Ypartial-unification")

Requirements

Running the blaze backend requires a modern, supported version of the JVM to build and run, as it relies on server APIs unavailable before JDK8u252. Any JDK newer than JDK8u252, including 9+ is supported.

Code of Conduct

http4s is proud to be a Typelevel project. We are committed to providing a friendly, safe and welcoming environment for all, and ask that the community adhere to the Scala Code of Conduct.

License

This software is licensed under the Apache 2 license, quoted below.

Copyright 2013-2021 http4s [https://http4s.org]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

[http://www.apache.org/licenses/LICENSE-2.0]

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Acknowledgments

YourKit

Special thanks to YourKit for supporting this project's ongoing performance tuning efforts with licenses to their excellent product.

http4s-dom's People

Contributors

armanbilge avatar http4s-steward[bot] avatar regadas avatar scala-steward avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

http4s-dom's Issues

addFetchEventListener: use Dispatcher instead of IORuntime?

I was just checking out what ServiceWorker provides and noticed it hardcodes IO and requires IORuntime. Could this be replaced with F[_]: Async and creating a dispatcher? Or was it the entire point to keep SyncIO so that you can safely run the effect synchronously?

Versioning scheme?

Considering that:

  1. these modules depend on http4s 1.0 milestones
  2. they're been previously published under those versions

Track artifact size

It's easy enough to add a check to CI that the JS artifact is below some threshold. But it would be more meaningful longterm if these numbers could go somewhere and be tracked.

Publish against http4s v0.23.x

This is assuming that http4s/http4s#5285 is imminent. I think having a (stable) release against a stable http4s version will be a big deal and help win over some of the naysayers e.g. keynmol/http4s-laminar-stack#7 (comment) 😉

However, this opens a pandora's box of versioning problems (see also #2). I'm also acutely aware of the upcoming scala-js-dom v2.0.0 release, which will hopefully land sometime in October. Unfortunately, I think it's important that we support both while the ecosystem upgrades.

My proposal:

  1. Start http4s-dom series/0.1 against http4s 0.23.x and scala-js-dom 1.x.
  2. When scala-js-dom 2.0.0 arrives, start http4s-dom series/0.2.
  3. Continue publishing 1.0 milestones against http4s 1.0 milestones and scala-js-dom 2.x. If we don't keep our milestone numbers in sync with upstream http4s this will get really confusing, but it also prevents us from releasing on our own cadence. (Would it be weird to have minor milestone releases? e.g. 1.0.0-M28.1)
  4. Pray that there's never a http4s 0.24.x.

Reduce the impact of MimeDB on JS size

We are testing http4s for our scala.js browser app and it seems to produce a fairly big increase on the scala.js produced by scala.js. One of the contributors is the very large MimeDB which maybe not needed on the typical frontend app

Should we split MimeDB into jvm and js versions, with the latter having a minimal or empty set of mime types?

Maximum call stack size exceeded after `fullOptJS`

Reported by @buntec:

I now run into a “maximum call stack size exceeded” exception in one of the projects at work using ff4s when making a simple GET request using ‘client.expect’. The source map points to line 255 in ‘MediaType.scala’, which looks innocuous to me. According to the call stack this seems to happen during entity decoding. I’m using 0.23.11. Strangely enough, this only occurs in the fully optimized js bundle; not during development when using fastOpt.

This sounds a lot like:

If we look at the reported line:

object MediaType extends MimeDB {

https://github.com/http4s/http4s/blob/v0.23.11/core/shared/src/main/scala/org/http4s/MediaType.scala#L255

It leads us to our old friend:

The current workaround is to disable GCC in fullOptJS with:

scalaJSLinkerConfig ~= { _.withClosureCompilerIfAvailable(false) }

I would like to explore alternative minimizers to GCC such as ESBuild:
https://esbuild.github.io/api/#minify

I also have a plan to fix #30 in http4s/http4s#5273. It is quite a bit of work to do binary-compatibly, but feasible I think.

Create a `http4s-dom-circe` module?

Why, when we already have http4s-circe from the main repo already crossing for Scala.js?

Because http4s-circe uses Jawn for parsing. This makes sense there, because it enables a pure cross and also supports fancy features like parsing streams etc.

But, a Jawn dependency is bloat and almost definitely less performant. The idea here is to offer a light-weight circe integration module that uses JS-native JSON.parse instead (via circe-parser).

Considerations:

  1. Does Jawn measurably increase JS size or hurt performance? Probably, but would be good to actually verify this.
  2. Does this module even belong in dom? Browsers care most about JS size, but everyone cares about performance, which is also at issue. There's an argument this belongs upstream.

Support streaming requests

https://developer.chrome.com/articles/fetch-streaming-requests/

This will require some sort of feature test:

 const supportsRequestStreams = (() => {
    let duplexAccessed = false;
    
    const hasContentType = new Request('', {
      body: new ReadableStream(),
      method: 'POST',
      get duplex() {
        duplexAccessed = true;
        return 'half';
      },
    }).headers.has('Content-Type');
    
    console.log({ duplexAccessed, hasContentType });
    
    return duplexAccessed && !hasContentType;
  })();

Create some awesome service worker middlewares

For example, check out this example of using a service worker to serve requests from the browser cache API.

self.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.match(event.request)
      .then(function(response) {
        // Cache hit - return response
        if (response) {
          return response;
        }
        return fetch(event.request);
      }
    )
  );
});

Microsite is published with `fastOptJS`

This was the fix applied in #45 for #33. Hopefully it works, except now the site load an 11mb JS file which is ... not ideal. So we are still seeking a better solution to this problem (see #33 for more details).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.