Git Product home page Git Product logo

http's Introduction

Gleam HTTP

Types and functions for HTTP clients and servers!

HTTP Service Example

import gleam/http/elli
import gleam/http/response.{type Response}
import gleam/http/request.{type Request}
import gleam/bytes_builder.{type BytesBuilder}

// Define a HTTP service
//
pub fn my_service(_request: Request(t)) -> Response(BytesBuilder) {
  let body = bytes_builder.from_string("Hello, world!")

  response.new(200)
  |> response.prepend_header("made-with", "Gleam")
  |> response.set_body(body)
}

// Start it on port 3000 using the Elli web server
//
pub fn main() {
  elli.become(my_service, on_port: 3000)
}

Server adapters

In the example above the Elli Erlang web server is used to run the Gleam HTTP service. Here's a full list of the server adapters available, sorted alphabetically.

Adapter About
Mist Mist is a high performance pure Gleam HTTP 1.1 server
cgi cgi is a adapter for the Common Gateway Interface.
gleam_cowboy Cowboy is an Erlang HTTP2 & HTTP1.1 web server
gleam_elli Elli is an Erlang HTTP1.1 web server
gleam_plug Plug is an Elixir web application interface

Client adapters

Client adapters are used to send HTTP requests to services over the network. Here's a full list of the client adapters available, sorted alphabetically.

Adapter About
gleam_fetch fetch is a HTTP client included with JavaScript
gleam_hackney Hackney is a simple HTTP client for Erlang
gleam_httpc httpc is a HTTP client included with Erlang

http's People

Contributors

adz avatar bcpeinhardt avatar blond11516 avatar crowdhailer avatar cschembor3 avatar dmmulroy avatar gazler avatar giacomocavalieri avatar j3rn avatar jwsonic avatar lpil avatar michallepicki avatar nwjlyons avatar r0dr160hm avatar ryan-haskell avatar scripttease avatar sporto avatar weizhliu 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

http's Issues

Missing tests

Many of the functions in this library do not have unit tests. Let's add them!

Conflicting `None` definitions

The http module imports None from option.
And also defines SameSitePolicy.None.
When trying to run the tests I get:

error: Type mismatch
    �� /home/sebastian/Source/sporto/http/src/gleam/http.gleam:151:15
    �
151 �     userinfo: None,
    �               ^^^^

Expected type:

    Option(String)

Found type:

    SameSitePolicy

Add an origin function.

This might be a bit beyond the scope of this library but I always end up creating the following function. The purpose is to find the origin of a request, falling back to the referer header if origin is not present.

browsers may not send the Origin header, as in the following cases:

img tags will not send Origin headers unless the crossorigin attribute is set>
Chrome and Safari will not send Origin headers with same-origin GET requests
Firefox will not send the Origin header with any same-origin requests (bug)
Firefox will not send the Origin header with cross-origin form POSTs (bug)

However, in all of these cases, the browser does send a Referer header. We can make use of the Referer header, which browser-initiated requests may not spoof, in place of the missing Origin header

I would call it http.get_req_origin

Documentation example imports gleam/elli

gleam/elli is referenced, but there is no link to where you get this module.
I don't know how close this project is to being on hex, but even a link to the github project would be helpful

Scope of this library, stdlib integration

Stdlib inclusion

@lpil mentioned that I should use this library so that I was using a standard HTTP method type.
Probably the only way I would find this type was if it was in standard lib. It's so small I am very likely to just re-implement. Also if there is something that it is expected everyone should use then is that not an argument for inclusion in stdlib?

What shouldn't this library do?

This question I think should be fairly similar regardless of if it will be included in stdlib or not, an http library on the gleam-lang repo will become the defacto standard

I am currently working on a Request and Response Type in midas, and the set of associated utilities e.g http.get_header, http.set_header etc. Would you be interested in a PR to add these to this project?

Add a `get_resp_cookie`

Missing the ability to fetch cookie information from a response.
Should ignore unknown attributes as specified in spec

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.